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

Read node names in XML

65
Hi,

Using LINQ to XML how to read XML node names??

I have the Following XML
Expand|Select|Wrap|Line Numbers
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3. <OrderDocument>
  4.   <rows>
  5.     <OrderDocumentRow>
  6.         <number>1</number>
  7.         <Cost>
  8.           <code>11</code>
  9.           <type>0</type>
  10.           <isDefault>false</isDefault>
  11.           <decimalTotal>0</decimalTotal>
  12.         </Cost>
  13.         <Order>
  14.           <code>88</code>
  15.           <type>0</type>
  16.           <isDefault>false</isDefault>
  17.           <decimalTotal>0</decimalTotal>
  18.         </Order>
  19.         <article>abc</article>
  20.       </OrderDocumentRow>
  21.   </rows>
  22. </OrderDocument>
  23.  
I want to get all the node names inside <OrderDocumentRow>.
i.e.
1)number
2)Cost
3)Order
4)article etc..
How to get the node name list?

thank you,
Veena
Jul 16 '10 #1

✓ answered by veenna

you can use the following code

Expand|Select|Wrap|Line Numbers
  1. strArray = new string[arraySize];
  2. XmlReader reader = XmlReader.Create(new StringReader(your XML));
  3. while (reader.Read())
  4. {
  5.   if (reader.NodeType == XmlNodeType.Element)
  6.   { 
  7.     strArray[cnt] = reader.Name;
  8.     cnt++;
  9.   }
  10. }
  11.  
Reagards
Veena

3 1943
veenna
65
you can use the following code

Expand|Select|Wrap|Line Numbers
  1. strArray = new string[arraySize];
  2. XmlReader reader = XmlReader.Create(new StringReader(your XML));
  3. while (reader.Read())
  4. {
  5.   if (reader.NodeType == XmlNodeType.Element)
  6.   { 
  7.     strArray[cnt] = reader.Name;
  8.     cnt++;
  9.   }
  10. }
  11.  
Reagards
Veena
Jul 17 '10 #2
veenna
65
hi,

Is there any way to read the Xml in the following format
1. Number
2. Cost
3. Cost.Code
4. Cost.Type
5. Cost.isDefault
6. Cost.decimalTotal
7. Order
8. Order.Code
etc..

Regards,
Veena
Jul 22 '10 #3
Jyoti Ballabh
115 100+
@veenna
yea, it's feasible. You can use it. I am glad you answered it yourself.
Jul 22 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Alex | last post by:
Hello, I don't have sufficient experience with XSLT, and would really appreciate somebody's help in me giving ideas on solving a problem I have. Let's consider the following XML file: ...
6
by: Carmine | last post by:
When I issue a db2 list db directory command, most of the node names are wrong. Is this a bug in Db2 v7 or is there something that I am missing? Thanx...
6
by: Mark | last post by:
I want the VB.Net program to read and file names from a directory. I thought the best thing to do was to place these file names into a "temporary" MS Access database for sorting, etc. So I'm...
6
by: Treasure NextDoor | last post by:
Hey, I"m just getting into DB2 and I'm not getting the node name alias thing. Are they just arbitrary? Something used for the purposes of easy human recognition? On the server side, it seems...
3
by: avanti | last post by:
Hi, I have an application that has a tag hierarchy that is pulled from the database and displayed in a treeview. I want to enable the user to add nodes (tags) to this treeview at runtime and...
0
by: HP17 | last post by:
Hi all, I am a bit desperate already trying to display a XML file using XSLT. I create a table and use <xsl:for-each> to extract every element node. This is working fine. What I want now is so...
1
by: bero81 | last post by:
hi to all, i should read the names of the active sheets in vb6. for example: i've got in a excel file 3 sheets:pippo,pippo1,pippo2 my routine should count the number of the sheets and return...
0
by: bero81 | last post by:
Hi to everyboby, how can i read the names of excel sheets with vb6?i'm using from my references Microsoft excel 11.0 object library.. could someone help me,please?
1
by: cbz9633 | last post by:
hi i want to read a folder name, after that read folder names within that folder and at last the file name and access it, that i know but i dont know how to read a folder name. please help
0
by: Kavitha Sudhershan | last post by:
hi, i wanna read the node values from xml. As per my code i can read the node values in first child node and for the next node am not able to read the node values. pls help me. i'll paste the code...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.