Advertisement
Guest User

Untitled

a guest
Sep 1st, 2015
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <ns0:Entity xmlns:ns0="http://schemas.mycompany.com/1.0">
  3. <ns0:Data>
  4. <Address_Id xmlns:ns0="http://schemas.mycompany.com/1.0">7</Address_Id>
  5. <Customer_Id xmlns:ns0="http://schemas.mycompany.com/1.0">67</Customer_Id>
  6. <CustomerName xmlns:ns0="http://schemas.mycompany.com/1.0">My Customer 1</CustomerName>
  7. </ns0:Data>
  8. </ns0:Entity>
  9.  
  10. private static string GetValue_Attempt1(XPathDocument xPathDocument, string xpathExpression)
  11. {
  12. var xpathNavigator = xPathDocument.CreateNavigator();
  13. var xpathNodeIterator = xpathNavigator.Select(xpathExpression);
  14. xpathNodeIterator.MoveNext();
  15. return xpathNodeIterator.Current.Value;
  16. }
  17.  
  18. private static string GetValue_Attempt2(XPathDocument xPathDocument, string xpathExpression)
  19. {
  20. var xpathNavigator = xPathDocument.CreateNavigator();
  21. var xpathNodeIterator = xpathNavigator.Select(xpathExpression);
  22. xpathNodeIterator.MoveNext();
  23. var nodesNavigator = xpathNodeIterator.Current;
  24. var nodesText = nodesNavigator.SelectDescendants(XPathNodeType.Text, false);
  25. nodesText.MoveNext();
  26. return nodesText.Current.Value;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement