XPATH complaining...

  • 13 years ago

    I have a VB.net application using an API and getting back large amounts of XML.

    In my VB I use code like this to get a list of nodes and then a FOR EACH loop to go through them...

    Dim XMLNodeList as XML.XMLNodeList = XMLReply.SelectNodes("//Book")

    This would get me a list of the <Book> nodes for me to play with.

    This works fine.

    The problem I have is that the XML returned from this one API has nodes with names like <hello:world> or <big:problem>

    The words don't matter. The point is that they have colons : in them... When I now run the above code to get my list it throws a big error like this

    Run-time exception thrown : System.Xml.XPath.XPathException - Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function.

    So I am guessing I need to escape my XPATH somehow or find another way....

    Any ideas anybody. I have been scratching my head on this for way too long already

    Thanks in advance

    Tom.

  • 13 years ago

    Been awhile since I played with xml, but can't you simply use a global replace on the xml returned (say "_" for ":"), before you then start selecting nodes?

    Joe 

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.” - Tom Cargill