473,396 Members | 2,052 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.

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 10662
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Robert Mark Bram | last post by:
Hi All! In the code below, I am reading in an xhtml document and attempting to use selectNodes to find a <p id="rmb"> node.. But the result is: 2 - */* 0 - */p Can anyone suggest what I...
5
by: Rajiv Das | last post by:
Hi, I am trying to incorporate Really Simple Syndicate (RSS) news into my asp (not asp.net) based website. Since RSS is basically XML, I am trying to open the xml file and parse it. On Asp.net the...
4
by: Gismo | last post by:
I have got file raport.rld which is an XML file generated by MS Reporting Services. The problem is: in this file are tags from two different namespaces ...
8
by: e-mid | last post by:
i want to get childs of specific xml node. normally i use xmlNodeList fooList = myNode.SelectNodes("foo"); but in compactframework , there is no selectNodes() method or selectSingleNode()...
2
by: Dave | last post by:
Hi, Is there an easier way to pull a subset of nodes from one XmlDocument to another? I have the code below but would like to know if there is a more streamlined method. Thanks, Dave ...
1
by: TT (Tom Tempelaere) | last post by:
Hi there, I load an Xml document into an XmlDocument object. I look up some nodes using SelectNodes/SelectSingleNode, and I modify the InnerText property. After this I call the XmlDocument.Save...
0
by: paulnamroud | last post by:
Dear Sir, I have a problem while parsing my XML file. I can read all nodes except the one called "Color". I have a node called "Color" with an attribute "l" to determine the language is frensh...
0
by: jgill | last post by:
Hello, To start with here is the code: Public Function Paymentget (s12MoRate) strCompanyCode = objXML.selectSingleNode("policy/companyCode").text strState =...
1
by: JB | last post by:
Does anyone know why this code works in example A but not in example B ? Is this a problem with special characters within the data values? A) Set xmlNodeList =...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.