Xpath with namespaces giving odd results

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Leafy
    New Member
    • Jan 2009
    • 2

    Xpath with namespaces giving odd results

    Hi Folks! I sure hope someone can guide me on this issue.

    Here is the XML document I'm working from (nda.xml):
    [code=xml]
    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelop e xmlns:soap="htt p://www.w3.org/2003/05/soap-envelope" xmlns:loc="http ://localhost:2680/">
    <soap:Header/>
    <soap:Body>
    <loc:CreateND A>
    <loc:docname>re m12345</loc:docname>
    <loc:encodeddat a>aaabbbcccddde eefff</loc:encodeddata >
    <!--Zero or more repetitions:-->
    <loc:parmeters> value1</loc:parmeters>
    <loc:parmeters> value2</loc:parmeters>
    <loc:parmeters> value3</loc:parmeters>
    </loc:CreateNDA>
    </soap:Body>
    </soap:Envelope>


    I'm writing this process in VB.NET. Here is my code:

    Dim fs As New FileStream("C:\ NDA\logs\rem999 9.log", FileMode.Create New, FileAccess.Writ e)
    Dim w As New StreamWriter(fs )
    Dim doc = New XPathDocument(" C:\NDA\nda.xml" )
    Dim nav = doc.CreateNavig ator()
    Dim xmlManager = New XmlNamespaceMan ager(nav.NameTa ble)

    xmlManager.AddN amespace("loc", "http://localhost:2680/")
    xmlManager.AddN amespace("soap" , "http://www.w3.org/2003/05/soap-envelope")
    Dim xpathExpress = nav.Compile("//soap:Envelope/soap:Body/loc:CreateNDA/loc:docname")
    xpathExpress.Se tContext(xmlMan ager)

    Dim xIterator = nav.Select(xpat hExpress)
    w.WriteLine(xIt erator.Current. Value)
    [/code]
    When this code excutes, I get the following results:
    "rem12345aaabbb cccdddeeefffval ue1value2value3 "

    With an xpathExpress variable set to "//soap:Envelope/soap:Body/loc:CreateNDA/loc:docname" I would expect my results to be equal to "rem12345" only.

    When I change the xpathExpress to point to "//soap:Envelope/soap:Body/loc:CreateNDA/loc:encodeddata " the results are the same "rem12345aaabbb cccdddeeefffval ue1value2value3 ". In this case, I would expect my results to be equal to "aaabbbcccdddee efff".

    I assume there is something wrong with my code, but I'm new to XML and Xpath. Anyone have any thoughts on why I'm getting the results I am?

    Any help is greatly apprciated!!

    Thanks!
    Leafy
    Last edited by pbmods; Jan 12 '09, 12:27 AM. Reason: Added CODE tags.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    you could try the XPath directly on your xml file (using a very basic xslt stylesheet) to test, what the result is there. (If you're using Firefox you may employ the "Get XSL Result" plugin). if the XPath is ok there, then it's something with the VB code....

    regards

    Comment

    • jkmyoung
      Recognized Expert Top Contributor
      • Mar 2006
      • 2057

      #3
      The value of the root node is all of the text nodes under it.

      Can you show us how you are setting the xIterator's current position?

      Comment

      Working...