Connecting Tech Pros Worldwide Help | Site Map

Need help with XML.XPath - SelectChildren method

  #1  
Old August 19th, 2008, 09:25 PM
Alexey Titov
Guest
 
Posts: n/a
Hi :)

I need help selecting particular nodes with the SelectChildren method
I get a simple xml from the web (excerpt):

<ab:store>
<ab:goods>

<ab:icecream>
<ab:flavor_01>
100
</ab:flavor_01>
<ab:flavor_02>
200
</ab:flavor_02>
<ab:flavor_03>
300
</ab:flavor_03>
</ab:icecream>

<ab:chocolate>
<ab:flavor_01>
100
</ab:flavor_01>
<ab:flavor_02>
200
</ab:flavor_02>
<ab:flavor_03>
300
</ab:flavor_03>
</ab:chocolate>


</ab:goods>
</ab:store>


Using this code:


Dim strNamespaceURI As String = "http://www.site.com/schema/"

Dim objDocument As XPathDocument = New
XPathDocument("http://www.site.com/document")

Dim objNavigator As XPathNavigator = objDocument.CreateNavigator()

Dim objNamespaceManager As XmlNamespaceManager = New
XmlNamespaceManager(objNavigator.NameTable)

objNamespaceManager.AddNamespace("ab", strNamespaceURI)

Dim objIterator As XPathNodeIterator =
objNavigator.Select("/ab:store/ab:goods", objNamespaceManager)

--- till now everything works fine, objIterator is fine, I can do with it
whatever I want

While objIterator.MoveNext()

--- then I try to get objIterator's children

Dim objIterator_Sub As XPathNodeIterator =
objIterator.Current.SelectChildren("ab:icecream", strNamespaceURI)

--- now objIterator_Sub doesn't return any nodes :( - tho it has 3 children

can any1 help me please - how do I get node's children with <exactly>
SelectChildren(name as string, namespaceuri as string) ...
calling it like SelectChildren(XPathNodeType.All) works fine - but it's no
use to me.

TIA


  #2  
Old August 20th, 2008, 08:25 AM
Pavel Minaev
Guest
 
Posts: n/a

re: Need help with XML.XPath - SelectChildren method


On Aug 19, 11:24*pm, "Alexey Titov" <hc...@yahoo.comwrote:
Quote:
I need help selecting particular nodes with the SelectChildren method
I get a simple xml from the web (excerpt):
>
<ab:store>
* * <ab:goods>
>
* * * * <ab:icecream>
* * * * * * <ab:flavor_01>
* * * * * * * * 100
* * * * * * </ab:flavor_01>
* * * * * * <ab:flavor_02>
* * * * * * * * 200
* * * * * * </ab:flavor_02>
* * * * * * <ab:flavor_03>
* * * * * * * * 300
* * * * * * </ab:flavor_03>
* * * * </ab:icecream>
>
* * * * <ab:chocolate>
* * * * * * <ab:flavor_01>
* * * * * * * * 100
* * * * * * </ab:flavor_01>
* * * * * * <ab:flavor_02>
* * * * * * * * 200
* * * * * * </ab:flavor_02>
* * * * * * <ab:flavor_03>
* * * * * * * * 300
* * * * * * </ab:flavor_03>
* * * * </ab:chocolate>
>
* * </ab:goods>
</ab:store>
>
Using this code:
>
Dim strNamespaceURI As String = "http://www.site.com/schema/"
>
Dim objDocument As XPathDocument = New
XPathDocument("http://www.site.com/document")
>
Dim objNavigator As XPathNavigator = objDocument.CreateNavigator()
>
Dim objNamespaceManager As XmlNamespaceManager = New
XmlNamespaceManager(objNavigator.NameTable)
>
objNamespaceManager.AddNamespace("ab", strNamespaceURI)
>
Dim objIterator As XPathNodeIterator =
objNavigator.Select("/ab:store/ab:goods", objNamespaceManager)
>
--- till now everything works fine, objIterator is fine, I can do with it
whatever I want
>
While objIterator.MoveNext()
>
--- then I try to get objIterator's children
>
*Dim objIterator_Sub As XPathNodeIterator =
objIterator.Current.SelectChildren("ab:icecream", strNamespaceURI)
Here's your problem. The first argument of SelectChildren is not an
XPath expression - _local_ name of the child elements to retrieve. You
do not need the namespace prefix here (and you specify the namespace
anyway in the second argument). SelectChildren("icecream",
strNamespaceURI) should do fine. Or, you can use Select() instead of
SelectChildren: Select("ab:icecream", objNamespaceManager) - and here
"ab:icecream" is an XPath expression.

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help on looping throug a xml file to find a specific innerxml janhm answers 15 November 17th, 2005 02:12 AM
Need help ASAP.....Messagebox problems. Tressa answers 4 November 16th, 2005 03:13 PM
XML to DataSet please help with selection Arthur Dzhelali answers 2 November 12th, 2005 02:59 AM
Help with xslt syntax error Chris Kettenbach answers 4 August 25th, 2005 11:15 PM
Need help with PHP DOMXML - get_elements_by_tagname MegaZone answers 4 July 17th, 2005 02:20 AM