Read node names in XML

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • veenna
    New Member
    • Dec 2007
    • 65

    Read node names in XML

    Hi,

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

    I have the Following XML
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <OrderDocument>
      <rows>
        <OrderDocumentRow>
            <number>1</number>
            <Cost>
              <code>11</code>
              <type>0</type>
              <isDefault>false</isDefault>
              <decimalTotal>0</decimalTotal>
            </Cost>
            <Order>
              <code>88</code>
              <type>0</type>
              <isDefault>false</isDefault>
              <decimalTotal>0</decimalTotal>
            </Order>
            <article>abc</article>
          </OrderDocumentRow>
      </rows>
    </OrderDocument>
    I want to get all the node names inside <OrderDocumentR ow>.
    i.e.
    1)number
    2)Cost
    3)Order
    4)article etc..
    How to get the node name list?

    thank you,
    Veena
  • veenna
    New Member
    • Dec 2007
    • 65

    #2
    you can use the following code

    Code:
    strArray = new string[arraySize];
    XmlReader reader = XmlReader.Create(new StringReader(your XML));
    while (reader.Read())
    {
      if (reader.NodeType == XmlNodeType.Element)
      { 
        strArray[cnt] = reader.Name;
        cnt++;
      }
    }
    Reagards
    Veena

    Comment

    • veenna
      New Member
      • Dec 2007
      • 65

      #3
      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.decimalTot al
      7. Order
      8. Order.Code
      etc..

      Regards,
      Veena

      Comment

      • Jyoti Ballabh
        Banned
        New Member
        • Jul 2010
        • 115

        #4
        Originally posted by veenna
        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.decimalTot al
        7. Order
        8. Order.Code
        etc..

        Regards,
        Veena
        yea, it's feasible. You can use it. I am glad you answered it yourself.

        Comment

        Working...