469,342 Members | 5,295 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,342 developers. It's quick & easy.

Problem with SelectNodes / SelectSingleNode

Ben
Hi

We have the XML Below

<Products>
<Item Code="1">
<PN>Name</PN>
<PC>ProductCode</PC>
<MC>Manufacturer</MC>
......
</Item>
</Products>

I am trying to get the select nodes to work, basically I only want to select
items where MC = 'Manufacturer'.

The code below does not error but does not return any results, i am fearful
that it is returning the child nodes of MC of which there are none.
doc.Load(Server.MapPath(cstrXMLManuf))

Dim doc As New XmlDocument
strXMLRequest = "Products/Item[./MC='Manufacturer']"
For Each n As XmlNode In doc.SelectNodes(String.Format(strXMLRequest))

strBody = n.SelectSingleNode("PC").InnerText
x = n.SelectSingleNode("PN").InnerText
.....

Any help would be much appreicated.

Thanks
B
May 6 '07 #1
3 10319
Ben wrote:
<Products>
<Item Code="1">
<PN>Name</PN>
<PC>ProductCode</PC>
<MC>Manufacturer</MC>
......
</Item>
</Products>

I am trying to get the select nodes to work, basically I only want to select
items where MC = 'Manufacturer'.

The code below does not error but does not return any results, i am fearful
that it is returning the child nodes of MC of which there are none.
doc.Load(Server.MapPath(cstrXMLManuf))

Dim doc As New XmlDocument
strXMLRequest = "Products/Item[./MC='Manufacturer']"
For Each n As XmlNode In doc.SelectNodes(String.Format(strXMLRequest))

strBody = n.SelectSingleNode("PC").InnerText
x = n.SelectSingleNode("PN").InnerText
The code and the XPath expressions are correct in my view so I can't
tell what goes wrong. Make sure you do not have a default namespace
declaration (e.g.
<Products xmlns="someURI">
) in the XML document respectively if you have one then make sure you
use an XmlNamespaceManager.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
May 7 '07 #2
Ben
Hi Martin

Thanks for your post.

It turned out to be a Case Sensitivity issue with the 'Manufacturer' text,
is there any way around this; ensuring that 'Manufacturer' and
'manufacturer' are both picked up?

Thanks
B
"Martin Honnen" <ma*******@yahoo.dewrote in message
news:OD******************@TK2MSFTNGP05.phx.gbl...
Ben wrote:
><Products>
<Item Code="1">
<PN>Name</PN>
<PC>ProductCode</PC>
<MC>Manufacturer</MC>
......
</Item>
</Products>

I am trying to get the select nodes to work, basically I only want to
select items where MC = 'Manufacturer'.

The code below does not error but does not return any results, i am
fearful that it is returning the child nodes of MC of which there are
none.
doc.Load(Server.MapPath(cstrXMLManuf))

Dim doc As New XmlDocument
strXMLRequest = "Products/Item[./MC='Manufacturer']"
For Each n As XmlNode In doc.SelectNodes(String.Format(strXMLRequest))

strBody = n.SelectSingleNode("PC").InnerText
x = n.SelectSingleNode("PN").InnerText

The code and the XPath expressions are correct in my view so I can't tell
what goes wrong. Make sure you do not have a default namespace declaration
(e.g.
<Products xmlns="someURI">
) in the XML document respectively if you have one then make sure you use
an XmlNamespaceManager.
--

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

May 7 '07 #3
Ben wrote:
It turned out to be a Case Sensitivity issue with the 'Manufacturer' text,
is there any way around this; ensuring that 'Manufacturer' and
'manufacturer' are both picked up?
XPath has a translate function that can help in that case although you
have to list all characters you want to translate e.g.

strXMLRequest = "Products/Item[translate(MC,
'ABCDEFGHIJKLMNOPQRSTUXWXYZ', 'abcdefghijklmnopqrstuvwxyz')
='manufacturer']"

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
May 7 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Robert Mark Bram | last post: by
5 posts views Thread by Rajiv Das | last post: by
4 posts views Thread by Gismo | last post: by
8 posts views Thread by e-mid | last post: by
1 post views Thread by TT (Tom Tempelaere) | last post: by
reply views Thread by paulnamroud | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.