473,385 Members | 1,727 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,385 software developers and data experts.

SelectSingleNode question

I am somewhat new to extracting data from an XML document in .Net.

My document looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<RMA-Standard>
<IncomeData>
<NetSales>64000000</NetSales>
<COGS>80.0</COGS>
<ProfitBeforeTax>6.0</ProfitBeforeTax>
</IncomeData>
</RMA-Standard>

I tried to do the following:
Dim _lNode As XmlNode
Dim _sNodeValue As String
Dim root As XmlElement = doc.DocumentElement
_sNodeValue = doc.SelectSingleNode("RMA-Standard\IncomeData\NetSales").InnerText()

The error I get is that the node does not exist. Basically, all I want to do is get the value out of that node.

Is my syntax wrong? I have seen some examples with a 'descendant'. Not sure what that is.

Thanks.

Norton

Nov 12 '05 #1
2 3302
Use frontslash rather than backslash to separate segments in the XPath.
Oh, and InnerText is a property, so:
_sNodeValue =
doc.SelectSingleNode("RMA-Standard/IncomeData/NetSales").InnerText
But since you already have a variable pointing to the root, this is more
efficient:
_sNodeValue = root.SelectSingleNode("IncomeData/NetSales").InnerText

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"TheNortonZ" <th********@hotmail.com> wrote in message
news:u6**************@tk2msftngp13.phx.gbl...
I am somewhat new to extracting data from an XML document in .Net.

My document looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<RMA-Standard>
<IncomeData>
<NetSales>64000000</NetSales>
<COGS>80.0</COGS>
<ProfitBeforeTax>6.0</ProfitBeforeTax>
</IncomeData>
</RMA-Standard>

I tried to do the following:
Dim _lNode As XmlNode
Dim _sNodeValue As String
Dim root As XmlElement = doc.DocumentElement
_sNodeValue =
doc.SelectSingleNode("RMA-Standard\IncomeData\NetSales").InnerText()
The error I get is that the node does not exist. Basically, all I want to do
is get the value out of that node.
Is my syntax wrong? I have seen some examples with a 'descendant'. Not sure
what that is.
Thanks.
Norton
Nov 12 '05 #2
Hi

You have your forward and backward slahes mixed up - you need Unix style
ones! So / instead of \.

HTH

Nigel Armstrong

"TheNortonZ" wrote:
I am somewhat new to extracting data from an XML document in .Net.

My document looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<RMA-Standard>
<IncomeData>
<NetSales>64000000</NetSales>
<COGS>80.0</COGS>
<ProfitBeforeTax>6.0</ProfitBeforeTax>
</IncomeData>
</RMA-Standard>

I tried to do the following:
Dim _lNode As XmlNode
Dim _sNodeValue As String
Dim root As XmlElement = doc.DocumentElement
_sNodeValue = doc.SelectSingleNode("RMA-Standard\IncomeData\NetSales").InnerText()

The error I get is that the node does not exist. Basically, all I want to do is get the value out of that node.

Is my syntax wrong? I have seen some examples with a 'descendant'. Not sure what that is.

Thanks.

Norton

Nov 12 '05 #3

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

Similar topics

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...
2
by: Edward Yang | last post by:
My XML document has a default namespace specified by xmlns="some_url". Here it is: <?xml version="1.0" encoding="utf-8" ?> <ssmproject name="sample" server="sql"...
6
by: Jay Bienvenu | last post by:
I have the following Visual Basic .NET code in an ASP.NET project: ' ... Dim xdStructure As XmlDocument Dim xnStructureRoot As XmlNode xdStructure = New XmlDocument...
7
by: Sashi | last post by:
Two questions: (1) I can pull the text of an XML element as a string just fine using code as such: strSomeString = myXmlDoc.SelectSingleNode("/Element1/Element2/Element3",...
1
by: Jesper | last post by:
Hi, I've read somewhere that try/catch shoudn't be used as an alternative to if clauses (maybe it was in C++ regi). However, when using XmlNode.SelectSingleNode(XPath expression) to get a node,...
2
by: Daniel Bass | last post by:
Hi all, I've got a scenario where I revert from a string, into an XmlDocument with the LoadXml method. From here I use the SelectSingleNode to get some node within the Xml Dom returned to me....
4
by: Robert Ludig | last post by:
My question is somewhat related to the previous question in this newsgroup: ...
0
by: compumate99 | last post by:
I am trying to parse the xml document using selectsinglenode method. I am doing this using Visual Foxpro >>> loResultXml = CreateObject("Microsoft.XMLDOM") With loResultXml .Async = .F. ...
5
by: Steve Harclerode | last post by:
I saw something in the Microsoft documentation for SelectNodes() that I've never noticed before today: ----- Return Value The first XmlNode that matches the XPath query or a null reference...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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...

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.