Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / March 2008

Tip: Looking for answers? Try searching our database.

Trying to use SelectNodes

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
lisa.liel@gmail.com - 06 Mar 2008 04:02 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.

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/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.