tags:

views:

49

answers:

2

Hello, I have xml like below

<ns:response xmlns:ns="http://example.com" xmlns:ax="http://example.com/xsd" >
    <ns:return type="mytype">
        <ax:roleID>1</ax:roleID>
        <ax:roleName>ADM</ax:roleName>
    </ns:return>
    <ns:return type="mytype">
        <ax:roleID>2</ax:roleID>
        <ax:roleName>USR</ax:roleName>
    </ns:return>
</ns:response>

How should look XPath expression for getting all roleNames (ADM, USR) ? That one below is not working

ns:response/ns:return/ax:roleName ns http://example.com ax http://example.com/xsd

I'm getting an exception:

'ns:response/ns:return/ax:roleName ns http://example.com ax http://example.com/xsd' has an invalid token.

A: 

I think you just need to specify the incex of ns:return as there's more than one:

ns:response/ns:return[1]/ax:roleName
pm_2
+2  A: 

If you are using XmlDocument.SelectNodes method, you should use "ns:response/ns:return/ax:roleName" as XPath and add the namespaces to an XmlNamespaceManager:

man.AddNamespace("ns", "http://example.com");
man.AddNamespace("ax", "http://example.com/xsd");
var set = doc.SelectNodes("ns:response/ns:return/ax:roleName", man);
Hinek
I'm actually using XPathNodeIterator: XPathNavigator nav = doc.CreateNavigator(); XPathNodeIterator nodeIter = nav.Select(expression);
Jarek Waliszko