Avatar of Adnan
Adnan
Flag for Norway

asked on 

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...
C#.NET ProgrammingXML

Avatar of undefined
Last Comment
Adnan

8/22/2022 - Mon