473,799 Members | 3,178 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

retrieve xmlnode value in XmlDocument

I have a xml file:
<OrderDetail TotalCount="2">
<ProductLine>
<LineNumber>1 </LineNumber>
<ProductNumber> A001</ProductNumber>
<ProductDescrip tion>17"VP171b</ProductDescript ion>
<ShipQuantity>1 00</ShipQuantity>
</ProductLine>
<ProductLine>
<LineNumber>2 </LineNumber>
<ProductNumber> A002</ProductNumber>
<ProductDescrip tion>17"VP171s</ProductDescript ion>
<ShipQuantity>2 00</ShipQuantity>
</ProductLine>
</OrderDetail>

And the node [ShipQuantity] xsd:integer

I want get [ShipQuantity] value in a int[] array,
How can I retrieve the 2 ProductLine's ShipQuantity value in it via C#
code?
use XmlNodeReader or XmlTextReader?

Thanks, David.

Nov 16 '05 #1
7 2377
David,

Your schema is almost completly a dataset.
(The header is not there)
I would try to use it as that when I was you.

Something as this
\\\
DataSet ds = new DataSet();
ds.ReadXml(@"C: \Test1\david.tx t");
int[] ships = new int[ds.Tables["ProductLin e"].Rows.Count];
for (int i = 0;i < ds.Tables["ProductLin e"].Rows.Count;i++ )
{
ships[i] = Convert.ToInt32
(ds.Tables["ProductLin e"].Rows[i]["ShipQuanti ty"]);
}
///
I hope this helps?

Cor
Nov 16 '05 #2
You could of course load the XML into an XmlDocument, iterate over all the
nodes and collect the quantities as you go. Another way is to use an XPath
query (warning: untested code follows):

string xmlText = ...;
XmlDocument xmlDoc = new xmlDoc;
xmlDoc.LoadXml( xmlText);

XmlNodeList nodes = xmlDoc.SelectNo des("//ShipQuantity");
int[] quantities = new int[nodes.Count];

for (int i = 0; i < nodes.Count; i++)
{
quantities[i] = int.Parse(nodes[i].InnerText);
}

Regards,
Sami

"David" <ca*******@wall a.com> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.com...
I have a xml file:
<OrderDetail TotalCount="2">
<ProductLine>
<LineNumber>1 </LineNumber>
<ProductNumber> A001</ProductNumber>
<ProductDescrip tion>17"VP171b</ProductDescript ion>
<ShipQuantity>1 00</ShipQuantity>
</ProductLine>
<ProductLine>
<LineNumber>2 </LineNumber>
<ProductNumber> A002</ProductNumber>
<ProductDescrip tion>17"VP171s</ProductDescript ion>
<ShipQuantity>2 00</ShipQuantity>
</ProductLine>
</OrderDetail>

And the node [ShipQuantity] xsd:integer

I want get [ShipQuantity] value in a int[] array,
How can I retrieve the 2 ProductLine's ShipQuantity value in it via C#
code?
use XmlNodeReader or XmlTextReader?

Thanks, David.

Nov 16 '05 #3
Thank you, Cor.
Do you know how to transfer a XmlDocument to a DataSet?
Because my xml data is from a XLANGMessage,
and I try it like this:

XLANGPart part = msg[0];
XmlDocument doc = (XmlDocument)pa rt.RetrieveAs(t ypeof(XmlDocume nt));
DataSet ds = new DataSet();
ds.ReadXml(doc) ;

But I can not put it in Dataset...
after I execute it, I got error message.

Thanks, David

Nov 16 '05 #4
Thank you, Sami.
But I got the error message:"Can not transfer XmlDocument to
XmlNodeList."

David

Nov 16 '05 #5
David,

When your xml file is as you showed, than that should do my sample, I tested
it before I have sent it.
(It was because it was in my opinion almost a dataset)

I made from your string a textfile and tested it before I have sand it.

So why you try it yourself in the same way as well.

Cor

"David" <ca*******@wall a.com>

news:11******** *************@c 13g2000cwb.goog legroups.com...
Thank you, Cor.
Do you know how to transfer a XmlDocument to a DataSet?
Because my xml data is from a XLANGMessage,
and I try it like this:

XLANGPart part = msg[0];
XmlDocument doc = (XmlDocument)pa rt.RetrieveAs(t ypeof(XmlDocume nt));
DataSet ds = new DataSet();
ds.ReadXml(doc) ;

But I can not put it in Dataset...
after I execute it, I got error message.

Thanks, David

Nov 16 '05 #6
text file using notebook however with the extention xml
Nov 16 '05 #7
I try this code, It is OK to trans dataset.

msg is a XLANGMessage:

XLANGPart part = msg[0];
XmlDocument doc = (XmlDocument)pa rt.RetrieveAs(t ypeof(XmlDocume nt));

XmlNodeReader xnr = new XmlNodeReader(d oc);
DataSet ds = new DataSet();
ds.ReadXml(xnr) ;

Thank you, Cor.

David.

Nov 16 '05 #8

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

Similar topics

1
7931
by: Brian | last post by:
Hello. I want to store some system settings in XML, but I am new to it. So far, I am able to retrieve the attributes, but not the elements they belong to (I hope my terminology is right). For example, I can retrieve "Clear", "AV1", "AV2", "BB", and "BB2" from the XML file below using this code, but I have no idea if they belong to the "GLOBAL", "AVIS", or "BOATING" elements. Can anyone tell me how to retrieve the element name, and...
3
33291
by: Andy | last post by:
Hello, I have the following example XML: <data> <package> <packageid>123</packageid> <package_article> <articleid>article1</articleid> </package_article> </package>
5
5101
by: Paul | last post by:
Here I have the definition of an XmlNode which is a property (PayPreference) on my Customer class containing an enum describing how the customer will pay. <PayPerference xsi:type="a4:Customer+CustomerPayOptions" xmlns:a4="http://schemas.microsoft.com/clr/nsassem/OsfDomain.Resources.Stage/OsfDomain%2C%20Version%3D1.0.0.1%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull">cash</PayPerference> I now want to add this XmlNode to a different...
1
3319
by: Andrus | last post by:
How to remove whole Xmlnode so that outer tags are also removed ? To reproduce, run the code. Observed result: <Query> <DataSourceName>DS1</DataSourceName> <QueryParameters> </QueryParameters>
0
9686
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
10475
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...
1
10222
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
10026
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9068
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...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4139
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3757
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.