[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 137
  • Last Modified:

How to read XML file attributes...

HI

I have a requirement to to read XML below, and i need help with couple of issues i have.

Here is my XML sample:
  <Entities>  
 <Entity Id="899" ExternalId="126" LongName="TINE Yog Melon/pasjon 2,5 kg" EntityTypeId="16" EntityTypeName="Produkt" ContainerId="4" ContainerName="Master katalog" OrganizationName="TINE SA" CategoryId="169" CategoryName="1230" CategoryLongName="TINE FruktYoghurt" CategoryPath="120 » 1230" CategoryLongNamePath="" ParentEntityId="169" ParentExternalId="1230" ParentExtensionEntityId="0" ParentExtensionEntityExternalId="" ParentExtensionEntityContainerId="0" ParentExtensionEntityContainerName="" ParentExtensionEntityCategoryId="0" ParentExtensionEntityCategoryPath="" ParentExtensionEntityCategoryLongNamePath="" Locale="no_NO_B" Action="Add">
      <Attributes>
        <Attribute Id="4041" [u]Name="M3_EAN_Dpak"[/u] LongName="EAN Dpak" InstanceRefId="-1" Sequence="-1" AttributeParentId="4001" AttributeParentName="M3" AttributeType="Simple" AttributeDataType="String" Locale="no_NO_B" Action="Add">
          <Values>
            <Value Id="0" Uom="" ValueRefId="-1" Sequence="-1" DisplayValue="" HasInvalidValue="False" Locale="no_NO_B" Action="Add"><![CDATA[[u]7038010001260[/u]]]></Value>
          </Values>
        </Attribute>
        <Attribute Id="4051" Name="M3_Artikkelnr" LongName="Artikkelnr" InstanceRefId="-1" Sequence="-1" AttributeParentId="4001" AttributeParentName="M3" AttributeType="Simple" AttributeDataType="String" Locale="no_NO_B" Action="Add">
          <Values>
            <Value Id="0" Uom="" ValueRefId="-1" Sequence="-1" DisplayValue="" HasInvalidValue="False" Locale="no_NO_B" Action="Add"><![CDATA[126]]></Value>
          </Values>
        </Attribute>
        <Attribute Id="4076" Name="M3_Navn" LongName="M3 Navn" InstanceRefId="-1" Sequence="-1" AttributeParentId="4001" AttributeParentName="M3" AttributeType="Simple" AttributeDataType="String" Locale="no_NO_B" Action="Add">
          <Values>
            <Value Id="0" Uom="" ValueRefId="-1" Sequence="-1" DisplayValue="" HasInvalidValue="False" Locale="no_NO_B" Action="Add"><![CDATA[2,5 KG YOG. MELON/PASJON SPANN]]></Value>
          </Values>
        </Attribute>
        <Attribute Id="4200" Name="TS_EPD_varenr" LongName="EPD varenr" InstanceRefId="-1" Sequence="-1" AttributeParentId="4003" AttributeParentName="Pricat" AttributeType="Simple" AttributeDataType="String" Locale="no_NO_B" Action="Add">
          <Values>
            <Value Id="0" Uom="" ValueRefId="-1" Sequence="-1" DisplayValue="" HasInvalidValue="False" Locale="no_NO_B" Action="Add"><![CDATA[2104115]]></Value>
          </Values>
        </Attribute>
      </Attributes>
      <Hierarchies></Hierarchies>
      <Relationships />
      <Extensions></Extensions>
    </Entity>
 </Entities>

Open in new window


I need to read all the attributes in Entety node, and that works fine, but i cant figure out how i can loop thrue all attributes in ChildNodes <Attribute>. I need to read <Attribute Name="xxxxxxx">  and i need to grab the <value> inside CDATA tag.

I need to loop all attributes below, and grab the attrube Name="", and value inside CDATA:
<Attribute Id="4041" [u]Name="M3_EAN_Dpak"[/u] LongName="EAN Dpak" InstanceRefId="-1" Sequence="-1" AttributeParentId="4001" AttributeParentName="M3" AttributeType="Simple" AttributeDataType="String" Locale="no_NO_B" Action="Add">
          <Values>
            <Value Id="0" Uom="" ValueRefId="-1" Sequence="-1" DisplayValue="" HasInvalidValue="False" Locale="no_NO_B" Action="Add"><![CDATA[[u]7038010001260[/u]]]></Value>
          </Values>
        </Attribute>
        <Attribute Id="4051" Name="M3_Artikkelnr" LongName="Artikkelnr" InstanceRefId="-1" Sequence="-1" AttributeParentId="4001" AttributeParentName="M3" AttributeType="Simple" AttributeDataType="String" Locale="no_NO_B" Action="Add">
          <Values>
            <Value Id="0" Uom="" ValueRefId="-1" Sequence="-1" DisplayValue="" HasInvalidValue="False" Locale="no_NO_B" Action="Add"><![CDATA[126]]></Value>
          </Values>
        </Attribute>
        <Attribute Id="4076" Name="M3_Navn" LongName="M3 Navn" InstanceRefId="-1" Sequence="-1" AttributeParentId="4001" AttributeParentName="M3" AttributeType="Simple" AttributeDataType="String" Locale="no_NO_B" Action="Add">
          <Values>
            <Value Id="0" Uom="" ValueRefId="-1" Sequence="-1" DisplayValue="" HasInvalidValue="False" Locale="no_NO_B" Action="Add"><![CDATA[2,5 KG YOG. MELON/PASJON SPANN]]></Value>
          </Values>
        </Attribute>
        <Attribute Id="4200" Name="TS_EPD_varenr" LongName="EPD varenr" InstanceRefId="-1" Sequence="-1" AttributeParentId="4003" AttributeParentName="Pricat" AttributeType="Simple" AttributeDataType="String" Locale="no_NO_B" Action="Add">
          <Values>
            <Value Id="0" Uom="" ValueRefId="-1" Sequence="-1" DisplayValue="" HasInvalidValue="False" Locale="no_NO_B" Action="Add"><![CDATA[2104115]]></Value>
          </Values>
        </Attribute>

Open in new window



Any help to solve this will be appriciated, and thanks in advance...
0
Adnan
Asked:
Adnan
  • 10
  • 4
  • 3
1 Solution
 
Fernando SotoRetiredCommented:
What classes are you using to read the Attributes anode and Child nodes. Are you using Linq to XML?
0
 
AdnanAuthor Commented:
Iam using XMLDocument, se code below:
 private static void readXMLFile(SPODataContext sp, string filePath)
        {
            //Create the XmlDocument.
            XmlDocument doc = new XmlDocument();
            doc.Load(filePath);

            XmlNodeList elemList = doc.GetElementsByTagName("Entity");
            for (int i = 0; i < elemList.Count; i++)
            {
                XmlNode elm = elemList[i];
                getEntity(elm);
            }
        }

        private static void getEntity(XmlNode elm)
        {
            for (int i = 0; i < elm.Attributes.Count; i++)
            {
                XmlAttribute entetyAttri = elm.Attributes[i];
                switch (entetyAttri.Name)
                {
                    case "Id":
                        Console.WriteLine(entetyAttri.Name);
                        Console.WriteLine(entetyAttri.Value);
                        break;
                    case "ExternalId":
                        Console.WriteLine(entetyAttri.Name);
                        Console.WriteLine(entetyAttri.Value);
                        break;
                    case "LongName":
                        Console.WriteLine(entetyAttri.Name);
                        Console.WriteLine(entetyAttri.Value);
                        break;
                    case "EntityTypeId":
                        Console.WriteLine(entetyAttri.Name);
                        Console.WriteLine(entetyAttri.Value);
                        break;
                    case "EntityTypeName":
                        Console.WriteLine(entetyAttri.Name);
                        Console.WriteLine(entetyAttri.Value);
                        break;
                    case "ContainerId":
                        Console.WriteLine(entetyAttri.Name);
                        Console.WriteLine(entetyAttri.Value);
                        break;
                    case "ContainerName":
                        Console.WriteLine(entetyAttri.Name);
                        Console.WriteLine(entetyAttri.Value);
                        break;
                    case "OrganizationName":
                        Console.WriteLine(entetyAttri.Name);
                        Console.WriteLine(entetyAttri.Value);
                        break;
                    case "CategoryId":
                        Console.WriteLine(entetyAttri.Name);
                        Console.WriteLine(entetyAttri.Value);
                        break;
                    case "CategoryName":
                        Console.WriteLine(entetyAttri.Name);
                        Console.WriteLine(entetyAttri.Value);
                        break;
                    case "CategoryLongName":
                        Console.WriteLine(entetyAttri.Name);
                        Console.WriteLine(entetyAttri.Value);
                        break;
                    case "CategoryPath":
                        Console.WriteLine(entetyAttri.Name);
                        Console.WriteLine(entetyAttri.Value);
                        break;
                    case "CategoryLongNamePath":
                        Console.WriteLine(entetyAttri.Name);
                        Console.WriteLine(entetyAttri.Value);
                        break;
                    case "ParentEntityId":
                        Console.WriteLine(entetyAttri.Name);
                        Console.WriteLine(entetyAttri.Value);
                        break;
                    case "ParentExternalId":
                        Console.WriteLine(entetyAttri.Name);
                        Console.WriteLine(entetyAttri.Value);
                        break;
                    case "ParentExtensionEntityId":
                        Console.WriteLine(entetyAttri.Name);
                        Console.WriteLine(entetyAttri.Value);
                        break;
                    case "ParentExtensionEntityExternalId":
                        Console.WriteLine(entetyAttri.Name);
                        Console.WriteLine(entetyAttri.Value);
                        break;
                    case "ParentExtensionEntityContainerId":
                        Console.WriteLine(entetyAttri.Name);
                        Console.WriteLine(entetyAttri.Value);
                        break;
                    case "ParentExtensionEntityContainerName":
                        Console.WriteLine(entetyAttri.Name);
                        Console.WriteLine(entetyAttri.Value);
                        break;
                    case "ParentExtensionEntityCategoryId":
                        Console.WriteLine(entetyAttri.Name);
                        Console.WriteLine(entetyAttri.Value);
                        break;
                    case "ParentExtensionEntityCategoryPath":
                        Console.WriteLine(entetyAttri.Name);
                        Console.WriteLine(entetyAttri.Value);
                        break;
                    case "ParentExtensionEntityCategoryLongNamePath":
                        Console.WriteLine(entetyAttri.Name);
                        Console.WriteLine(entetyAttri.Value);
                        break;
                    case "Locale":
                        Console.WriteLine(entetyAttri.Name);
                        Console.WriteLine(entetyAttri.Value);
                        break;
                    default:
                        Console.WriteLine("Default case");
                        break;
                }
            }
            XmlNodeList celm = elm.ChildNodes;
            getAttributes(celm);
        }


        public static int count;
        private static void getAttributes(XmlNodeList celm)
        {
            count = celm.Count;
            for (int i = 0; i <= celm.Count - 1; i++)
            {
                var childNd = celm[i].Name;
                if (childNd == "Attributes")
                {
                    for (int ci = 0; ci < celm.Count; ci++)
                    {
                        XmlNode clm = celm[ci].ChildNodes[ci];
                        if(clm != null)
                        {
                            for (int att = 0; att < clm.Attributes.Count; att++)
                            {
                                if (clm.Attributes[att].NodeType.ToString() == "Attribute")
                                {
                                    XmlAttribute entetyAttri = clm.Attributes[att];
                                    switch (entetyAttri.Name)
                                    {
                                        case "Name":
                                            Console.WriteLine(entetyAttri.Name);
                                            Console.WriteLine(entetyAttri.Value);
                                            break;

                                        default:
                                            Console.WriteLine("Default case");
                                            break;
                                    }
                                }
                            }
                        }
                    }
                }

                count++;
            }
        }

Open in new window

0
 
AdnanAuthor Commented:
Here is the XML full sample, with only one Entity, but there gona be hundreds of them, and attrube can be 1 or more...:

<?xml version="1.0" encoding="utf-8"?>
<Data Schema="RSXML4.1" xmlns="http://schemas.riversand.com/mdmcenter" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schemas.riversand.com/mdmcenter/RSXml4.1.xsd">
  <Entities>
    <Entity Id="899" ExternalId="126" LongName="TINE Yog Melon/pasjon 2,5 kg" EntityTypeId="16" EntityTypeName="Produkt" ContainerId="4" ContainerName="Master katalog" OrganizationName="TINE SA" CategoryId="169" CategoryName="1230" CategoryLongName="TINE FruktYoghurt" CategoryPath="120 » 1230" CategoryLongNamePath="" ParentEntityId="169" ParentExternalId="1230" ParentExtensionEntityId="0" ParentExtensionEntityExternalId="" ParentExtensionEntityContainerId="0" ParentExtensionEntityContainerName="" ParentExtensionEntityCategoryId="0" ParentExtensionEntityCategoryPath="" ParentExtensionEntityCategoryLongNamePath="" Locale="no_NO_B" Action="Add">
      <Attributes>
        <Attribute Id="4041" Name="M3_EAN_Dpak" LongName="EAN Dpak" InstanceRefId="-1" Sequence="-1" AttributeParentId="4001" AttributeParentName="M3" AttributeType="Simple" AttributeDataType="String" Locale="no_NO_B" Action="Add">
          <Values>
            <Value Id="0" Uom="" ValueRefId="-1" Sequence="-1" DisplayValue="" HasInvalidValue="False" Locale="no_NO_B" Action="Add"><![CDATA[7038010001260]]></Value>
          </Values>
        </Attribute>
        <Attribute Id="4051" Name="M3_Artikkelnr" LongName="Artikkelnr" InstanceRefId="-1" Sequence="-1" AttributeParentId="4001" AttributeParentName="M3" AttributeType="Simple" AttributeDataType="String" Locale="no_NO_B" Action="Add">
          <Values>
            <Value Id="0" Uom="" ValueRefId="-1" Sequence="-1" DisplayValue="" HasInvalidValue="False" Locale="no_NO_B" Action="Add"><![CDATA[126]]></Value>
          </Values>
        </Attribute>
        <Attribute Id="4076" Name="M3_Navn" LongName="M3 Navn" InstanceRefId="-1" Sequence="-1" AttributeParentId="4001" AttributeParentName="M3" AttributeType="Simple" AttributeDataType="String" Locale="no_NO_B" Action="Add">
          <Values>
            <Value Id="0" Uom="" ValueRefId="-1" Sequence="-1" DisplayValue="" HasInvalidValue="False" Locale="no_NO_B" Action="Add"><![CDATA[2,5 KG YOG. MELON/PASJON SPANN]]></Value>
          </Values>
        </Attribute>
        <Attribute Id="4200" Name="TS_EPD_varenr" LongName="EPD varenr" InstanceRefId="-1" Sequence="-1" AttributeParentId="4003" AttributeParentName="Pricat" AttributeType="Simple" AttributeDataType="String" Locale="no_NO_B" Action="Add">
          <Values>
            <Value Id="0" Uom="" ValueRefId="-1" Sequence="-1" DisplayValue="" HasInvalidValue="False" Locale="no_NO_B" Action="Add"><![CDATA[2104115]]></Value>
          </Values>
        </Attribute>
      </Attributes>
      <Hierarchies></Hierarchies>
      <Relationships />
      <Extensions></Extensions>
    </Entity>
</Entities>
</Data>

Open in new window

0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Fernando SotoRetiredCommented:
Can you use XDocument object instead of XMLDocument objects?
0
 
AdnanAuthor Commented:
Yes why not, but i havent used XDocument before, any sample you can show  for this XML?
0
 
AdnanAuthor Commented:
I tried it this way, but its returning null:

 private static void readXMLFile(SPODataContext sp, string filePath)
        {
           try
            {
                XDocument xdoc = XDocument.Load(filePath);
                var groupElements = from el in xdoc.Descendants().Elements("Entity") select el;

               // Console.WriteLine("");
            }
            catch(Exception exp)
            {
                Console.WriteLine(exp);
            }
        }

Open in new window

0
 
AdnanAuthor Commented:
Why iam getting result "null"  when i use XDocuemnt class:

 XDocument xdoc = XDocument.Load(filePath);
                //var groupElements = from el in xdoc.Descendants().Elements("Entity") select el;
                var query = xdoc.Descendants("Entities");

Open in new window



"Enumeration yielded no results"
0
 
Fernando SotoRetiredCommented:
It is most likely due to the xml namespace in the root node.

What is the Encoding of the full XML document you posted? There seems to be an invalid character on line 4 character position 288, a double greater then sign as one character hex value BB.
0
 
AdnanAuthor Commented:
Sorry i cant see the namespace, it is Encoding UTF-8

XML:

<?xml version="1.0" encoding="utf-8"?>
<Data Schema="RSXML4.1" xmlns="http://schemas.riversand.com/mdmcenter" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schemas.riversand.com/mdmcenter/RSXml4.1.xsd">
  <Entities>
    <Entity Id="899" ExternalId="126" LongName="TINE Yog Melon/pasjon 2,5 kg" EntityTypeId="16" EntityTypeName="Produkt" ContainerId="4" ContainerName="Master katalog" OrganizationName="TINE SA" CategoryId="169" CategoryName="1230" CategoryLongName="TINE FruktYoghurt" CategoryPath="120 » 1230" CategoryLongNamePath="" ParentEntityId="169" ParentExternalId="1230" ParentExtensionEntityId="0" ParentExtensionEntityExternalId="" ParentExtensionEntityContainerId="0" ParentExtensionEntityContainerName="" ParentExtensionEntityCategoryId="0" ParentExtensionEntityCategoryPath="" ParentExtensionEntityCategoryLongNamePath="" Locale="no_NO_B" Action="Add">
      <Attributes>
        <Attribute Id="4041" Name="M3_EAN_Dpak" LongName="EAN Dpak" InstanceRefId="-1" Sequence="-1" AttributeParentId="4001" AttributeParentName="M3" AttributeType="Simple" AttributeDataType="String" Locale="no_NO_B" Action="Add">
          <Values>
            <Value Id="0" Uom="" ValueRefId="-1" Sequence="-1" DisplayValue="" HasInvalidValue="False" Locale="no_NO_B" Action="Add"><![CDATA[7038010001260]]></Value>
          </Values>
        </Attribute>
        <Attribute Id="4051" Name="M3_Artikkelnr" LongName="Artikkelnr" InstanceRefId="-1" Sequence="-1" AttributeParentId="4001" AttributeParentName="M3" AttributeType="Simple" AttributeDataType="String" Locale="no_NO_B" Action="Add">
          <Values>
            <Value Id="0" Uom="" ValueRefId="-1" Sequence="-1" DisplayValue="" HasInvalidValue="False" Locale="no_NO_B" Action="Add"><![CDATA[126]]></Value>
          </Values>
        </Attribute>
        <Attribute Id="4076" Name="M3_Navn" LongName="M3 Navn" InstanceRefId="-1" Sequence="-1" AttributeParentId="4001" AttributeParentName="M3" AttributeType="Simple" AttributeDataType="String" Locale="no_NO_B" Action="Add">
          <Values>
            <Value Id="0" Uom="" ValueRefId="-1" Sequence="-1" DisplayValue="" HasInvalidValue="False" Locale="no_NO_B" Action="Add"><![CDATA[2,5 KG YOG. MELON/PASJON SPANN]]></Value>
          </Values>
        </Attribute>
        <Attribute Id="4200" Name="TS_EPD_varenr" LongName="EPD varenr" InstanceRefId="-1" Sequence="-1" AttributeParentId="4003" AttributeParentName="Pricat" AttributeType="Simple" AttributeDataType="String" Locale="no_NO_B" Action="Add">
          <Values>
            <Value Id="0" Uom="" ValueRefId="-1" Sequence="-1" DisplayValue="" HasInvalidValue="False" Locale="no_NO_B" Action="Add"><![CDATA[2104115]]></Value>
          </Values>
        </Attribute>
      </Attributes>
      <Hierarchies></Hierarchies>
      <Relationships />
      <Extensions></Extensions>
    </Entity>
</Entities>
</Data>

Open in new window

0
 
anarki_jimbelCommented:
Fernando Soto is talking about
xmlns="http://schemas.riversand.com/mdmcenter" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

Open in new window

in the Data root.

And I'm pretty sure he's right. If you remove namespaces from your xml you'll be able to read elements.

Or you will need to use XNamespace Class.
0
 
anarki_jimbelCommented:
Try something like:
    class Program
    {
        static void Main(string[] args)
        {
            readXMLFile("data.xml");
            Console.ReadLine();
        }

        private static void readXMLFile(string filePath)
        {
            try
            {
                XDocument xdoc = XDocument.Load(filePath);
                XNamespace nsSys = "http://schemas.riversand.com/mdmcenter";
                var entities = from el in xdoc.Descendants(nsSys + "Entity") 
                                    select new
                                    {
                                        Id=el.Attribute("Id").Value,
                                        LongName=el.Attribute("LongName").Value
                                    };

                foreach (var p in entities)
                    Console.WriteLine(p.ToString());

                Console.WriteLine("");
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp);
            }
        }
    }

Open in new window

0
 
Fernando SotoRetiredCommented:
When you did this
 XDocument xdoc = XDocument.Load(filePath);
                //var groupElements = from el in xdoc.Descendants().Elements("Entity") select el;
                var query = xdoc.Descendants("Entities");

Open in new window

did you not get an error? If not what XML document did you use?
0
 
AdnanAuthor Commented:
I managed to read the node <Entity>.

This code sample worked:
 private static void readXMLFile(SPODataContext sp, string filePath)
        {
           try
            {
                XDocument xdoc = XDocument.Load(filePath);
                var query = from d in xdoc.Descendants()
                            where d.Name.LocalName == "Entity"
                            select d;


                Console.WriteLine(query);
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp);
            }
        }

Open in new window

0
 
AdnanAuthor Commented:
Perfect anarki_jimbel, your sample worked as charm, but how can i grab the value from choldnodes:

f.exp

<Attribute Id="4041" Name="M3_EAN_Dpak" LongName="EAN Dpak" InstanceRefId="-1" Sequence="-1" AttributeParentId="4001" AttributeParentName="M3" AttributeType="Simple" AttributeDataType="String" Locale="no_NO_B" Action="Add">
          <Values>
            <Value Id="0" Uom="" ValueRefId="-1" Sequence="-1" DisplayValue="" HasInvalidValue="False" Locale="no_NO_B" Action="Add"><![CDATA[7038010001260]]></Value>
          </Values>
        </Attribute>

Open in new window



I need to grab the <Attribute> Name="M3_EAN_Dpak"
And value [CDATA[7038010001260]]

it can be one or more Attributes in one Entetity.
0
 
AdnanAuthor Commented:
to be more correct i need to grab Name and CDATA for each Attribute...
0
 
anarki_jimbelCommented:
Honestly, I'm not that experienced in this stuff. So my code might be not good enough, may be there are some more clever ways.
Anyway, try this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using System.IO;
using System.Xml;

namespace XDocTest
{
    class Program
    {
        static void Main(string[] args)
        {
            readXMLFile("data.xml");
            Console.ReadLine();
        }

        public class Entity
        {
            public string Id { get; set; }
            public string LongName { get; set; }
            public IEnumerable<Attribute> Attributes { get; set; }

        }
        public class Attribute
        {
            public string Id { get; set; }
            public string Name { get; set; }
            public IEnumerable<AttributeValue> Values { get; set; }
        }

        public class AttributeValue
        {
            public string CData { get; set; }
        }
        private static void readXMLFile(string filePath)
        {
            try
            {
                XDocument xdoc = XDocument.Load(filePath);
                XNamespace nsSys = "http://schemas.riversand.com/mdmcenter";
                var entities = from el in xdoc.Descendants(nsSys + "Entity") 
                                    select new Entity
                                    {
                                        Id=el.Attribute("Id").Value,
                                        LongName=el.Attribute("LongName").Value,
                                        Attributes = from a in el.Descendants(nsSys+"Attribute")
                                        select new Attribute
                                        {
                                            Id = a.Attribute("Id").Value,
                                            Name = a.Attribute("Name").Value,
                                            Values = from v in a.Descendants(nsSys + "Value")
                                                     select new AttributeValue
                                                     {
                                                         CData = v.Value
                                                     }
                                        }
                                    };

                foreach (Entity p in entities)
                {
                    Console.WriteLine(p.Id + " / " + p.LongName);
                    foreach (Attribute a in p.Attributes)
                    {
                        Console.WriteLine("\t" + "Name = " + a.Name);
                        foreach (AttributeValue v in a.Values)
                        {
                            Console.WriteLine("\t\t" + "CDATA = " + v.CData);
                        }
                    }
                }
                    

                Console.WriteLine("");
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp);
            }
        }
    }
}

Open in new window


Output
0
 
AdnanAuthor Commented:
Hi,

This did the job for me, now i understand bit more how to use XDocument class, thanks alot for your help....
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 10
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now