473,903 Members | 4,731 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with SelectNodes / SelectSingleNod e

Ben
Hi

We have the XML Below

<Products>
<Item Code="1">
<PN>Name</PN>
<PC>ProductCode </PC>
<MC>Manufacture r</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(cstrXM LManuf))

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

strBody = n.SelectSingleN ode("PC").Inner Text
x = n.SelectSingleN ode("PN").Inner Text
.....

Any help would be much appreicated.

Thanks
B
May 6 '07 #1
3 10725
Ben wrote:
<Products>
<Item Code="1">
<PN>Name</PN>
<PC>ProductCode </PC>
<MC>Manufacture r</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(cstrXM LManuf))

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

strBody = n.SelectSingleN ode("PC").Inner Text
x = n.SelectSingleN ode("PN").Inner Text
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 XmlNamespaceMan ager.
--

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*******@yaho o.dewrote in message
news:OD******** **********@TK2M SFTNGP05.phx.gb l...
Ben wrote:
><Products>
<Item Code="1">
<PN>Name</PN>
<PC>ProductCode </PC>
<MC>Manufacture r</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(Serve r.MapPath(cstrX MLManuf))

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

strBody = n.SelectSingleN ode("PC").Inner Text
x = n.SelectSingleN ode("PN").Inner Text

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 XmlNamespaceMan ager.
--

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,
'ABCDEFGHIJKLMN OPQRSTUXWXYZ', 'abcdefghijklmn opqrstuvwxyz')
='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
2802
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 am doing wrong?
5
2124
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 following code works seamlessly. I am running IIS 5.1 on Win Xp Sp1. ---------------------------------------------------------------------------- Dim objXMLNews set objXMLNews = Server.CreateObject("Msxml2.DomDocument.4.0") objXMLNews.async =...
4
8981
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 xmlns="http://schemas.microsoft.com/sqlserver/reporting/2003/10/reportdefini tion" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner"
8
6448
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() method. what else can i use instead?
2
6215
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 XmlNodeList nodeList = doc1.SelectNodes("//row"); foreach (XmlNode nodeCode in nodeList) { sb.Append(nodeCode.OuterXml);
1
1594
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 method on the XmlDocument object, BUT, the changes are NOT written! The resulting Xml document is identical to the original. Basically what I do is this:
0
1372
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 or english. Can anyone help me ? Thank you. Paul
0
1157
by: jgill | last post by:
Hello, To start with here is the code: Public Function Paymentget (s12MoRate) strCompanyCode = objXML.selectSingleNode("policy/companyCode").text strState = objXML.selectSingleNode("policy/insured/state").text set rsDownPayment = getCache("down_payment")
1
2193
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 = xmlParentNode.selectNodes("//PredecessorLink") B) Set xmlNodeList = xmlParentNode.selectNodes("//PredecessorLink") The data contains both values, but the code can't find the '\\winntpath\mypath\file.mpp' value...
0
9999
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11285
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10878
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10986
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9688
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8049
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5894
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4308
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.