473,396 Members | 1,895 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.

reading XML file?

VMI
If I have an XML document, how can I find out what the contents of a certain
tag is?

For example, if I have this:

<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<Table1>
<zip_code>00902</zip_code>
<addon_low>3121</addon_low>
<addon_high>3205</addon_high>
<rec_type>P</rec_type>
<prim_low>9023121</prim_low>
</Table1>
</NewDataSet>

How can I know what the contents of the addon_low node is? Is there any way
that I can check if XmlTextReader.Name equals "addon_low", then display
3205?

Thanks.
Nov 17 '05 #1
2 1318
I think the easist way is that you can create a C# class and serialize
the contents into an object, and check the contents of the property.

HTH.

VMI wrote:
If I have an XML document, how can I find out what the contents of a certain
tag is?

For example, if I have this:

<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<Table1>
<zip_code>00902</zip_code>
<addon_low>3121</addon_low>
<addon_high>3205</addon_high>
<rec_type>P</rec_type>
<prim_low>9023121</prim_low>
</Table1>
</NewDataSet>

How can I know what the contents of the addon_low node is? Is there any way
that I can check if XmlTextReader.Name equals "addon_low", then display
3205?

Thanks.

Nov 17 '05 #2
Hi VMI,
you could use an XPath expression to select the node, then read the inner
text to get the addon_low node value. i.e.

string strXml = @"<NewDataSet>
<Table1>
<zip_code>00902</zip_code>
<addon_low>3121</addon_low>
<addon_high>3205</addon_high>
<rec_type>P</rec_type>
<prim_low>9023121</prim_low>
</Table1>
</NewDataSet>";

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(strXml);

XmlNode addOnLow = xmlDoc.SelectSingleNode("/NewDataSet/Table1/addon_low");

string innerValue = addOnLow.InnerText;
Hope that helps
Mark R Dawson
http://www.markdawson.org

"VMI" wrote:
If I have an XML document, how can I find out what the contents of a certain
tag is?

For example, if I have this:

<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<Table1>
<zip_code>00902</zip_code>
<addon_low>3121</addon_low>
<addon_high>3205</addon_high>
<rec_type>P</rec_type>
<prim_low>9023121</prim_low>
</Table1>
</NewDataSet>

How can I know what the contents of the addon_low node is? Is there any way
that I can check if XmlTextReader.Name equals "addon_low", then display
3205?

Thanks.

Nov 17 '05 #3

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

Similar topics

4
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # to open a file and write to file # do f=open('xfile.txt','w') # this creates a file "object" and name it f. # the second argument of open can be
19
by: Lionel B | last post by:
Greetings, I need to read (unformatted text) from stdin up to EOF into a char buffer; of course I cannot allocate my buffer until I know how much text is available, and I do not know how much...
4
by: Oliver Knoll | last post by:
According to my ANSI book, tmpfile() creates a file with wb+ mode (that is just writing, right?). How would one reopen it for reading? I got the following (which works): FILE *tmpFile =...
6
by: Rajorshi Biswas | last post by:
Hi folks, Suppose I have a large (1 GB) text file which I want to read in reverse. The number of characters I want to read at a time is insignificant. I'm confused as to how best to do it. Upon...
7
by: John Dann | last post by:
I'm trying to read some binary data from a file created by another program. I know the binary file format but can't change or control the format. The binary data is organised such that it should...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
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...
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.