473,396 Members | 1,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Need help with XML.XPath - SelectChildren method

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
Aug 19 '08 #1
1 3531
On Aug 19, 11:24*pm, "Alexey Titov" <hc...@yahoo.comwrote:
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.

Aug 20 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: MegaZone | last post by:
I'm having some issues with PHP DOMXML - in particular the get_elements_by_tagname method. Now, the PGP docs on this are, well, sparse, so maybe I'm just doing something stupid. I thought this...
1
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for...
3
by: John R. | last post by:
I have an application written in C# and i am using MS XML DOM! I have a document with the following structure (only the <DicEntry> - Elements are important): <NewDataSet...
0
by: Luis Esteban Valencia Muñoz | last post by:
on my page I have a DropDownList and a label. My DropDownList is filled from an xml file using XPathNavigator. What I want to do is when the user selects a value from my DropDownList I want a...
3
by: Joe | last post by:
Hi I have a dataset with 2 tables and Relations What is the best way to flatten the 2 files to a new table or xml or file I can loop thru table1 and get the childrows or I can do an Xpath on...
1
by: Keith Patrick | last post by:
I'm converting over from using XmlNodes (specifically ConfigXmlNode, but the API uses XmlNode) to IXPathNavigable in some methods I have, but I'm finding in the process, that I can't seem to get...
2
by: Jiho Han | last post by:
I have an xml document as follows: <?xml version="1.0" encoding="utf-8" ?> <entityConfiguration xmlns="http://schemas.infinityinfo.com/entityconfiguration" version="1.0"> <entity...
3
by: abcd_68 | last post by:
Hi there, I'm using, for the first time, the JDK1.5 Xpath API. I need to find elements in a Hibernate-generated .hbm.xml file. These files come with a <!DOCTYPE header mentioning a remote URL....
0
by: cms3023 | last post by:
I have a DataGrid which displays data with the aid of a procedure. I have tested the procedure inside the database and it is working fine. The table inside the database has data that matches with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.