I have an XMLDocument. When I set a breakpoint in my code and check
doc.InnerText in the immediate window, it's definitely there.
But when I check doc.SelectNodes("//Children/BrowseNode").Count, it
gives me 0. I've tried variations on the theme, such as
doc.SelectNodes("//Children").Count, and it still comes up 0. Here's
the XML (slightly modified for length). Am I doing something wrong?
The XPath looks right to me.
Thanks,
Lisa
<?xml version="1.0" encoding="UTF-8"?>
<BrowseNodeLookupResponse xmlns="http://whatever.com">
<OperationRequest>
<HTTPHeaders>
<Header Name="UserAgent"></Header>
</HTTPHeaders>
<RequestId>10KDG692THQK3J142W77</RequestId>
<Arguments>
<Argument Name="Service" Value="AWSECommerceService"></Argument>
</Arguments>
<RequestProcessingTime>0.0126769542694092</RequestProcessingTime>
</OperationRequest>
<BrowseNodes>
<Request>
<IsValid>True</IsValid>
<BrowseNodeLookupRequest>
<BrowseNodeId>301668</BrowseNodeId>
</BrowseNodeLookupRequest>
</Request>
<BrowseNode>
<BrowseNodeId>301668</BrowseNodeId>
<Name>Styles</Name>
<Children>
<BrowseNode>
<BrowseNodeId>30</BrowseNodeId>
<Name>Alternative Rock</Name>
</BrowseNode>
<BrowseNode>
<BrowseNodeId>31</BrowseNodeId>
<Name>Blues</Name>
</BrowseNode>
<BrowseNode>
<BrowseNodeId>42</BrowseNodeId>
<Name>Soundtracks</Name>
</BrowseNode>
</Children>
</BrowseNode>
</BrowseNodes>
</BrowseNodeLookupResponse>
Martin Honnen - 06 Mar 2008 12:26 GMT
> I have an XMLDocument. When I set a breakpoint in my code and check
> doc.InnerText in the immediate window, it's definitely there.
[quoted text clipped - 10 lines]
> <?xml version="1.0" encoding="UTF-8"?>
> <BrowseNodeLookupResponse xmlns="http://whatever.com">
Your elements are in the namespace http://whatever.com so for XPath 1.0
to select them you need to choose a prefix and bind that prefix to the
namespace URI and use that prefix in XPath expressions.
With the .NET framework you do that as follows:
XmlNamespaceManager nsMgr = new XmlNamespaceManager(doc.NameTable);
nsMgr.AddNamespace("wh", "http://whatever.com");
XmlNodeList list = doc.SelectNodes("//wh:Children/wh:BrowseNode", nsMgr);

Signature
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/