XML: how to reach different fields with same name on the same level of hierarchy

Hi!

After deserializing the XML-document, I’m trying to update fields with new values. But, some of the fields (placed in the same level in hierarchy) are having the same nametag.

<Doc>
    <Description>
        <Code v="01" />
        <Text v="Test01" />
    </Description>
    <Description>
        <Code v="02" />
        <Text v="Test02" /> 
    </Description>
    <Description>
        <Code v="03" />
        <Text v="Test03" />
    </Description> 
</Doc>

I’m using XML_deserialized.Element(“Doc”).Element(“Description”).Element(“Text”).Attribute(“v”).Value to access the first instance of text(where code=01), but how to I tailor my syntax to reach the second and third instance (where code=02 and code=03)?

Edit: the code values are static, and used to identify the different fields. 01 e.x. is the identifier for name, so the text field related to code=01 should be updated with a name value. Code=02 is for adress and Code=03 is for telephone.

Please help me! :slight_smile:

@anders.knudsen
give a try on:
XML_deserialized.Element(“Doc”).Elements(“Description”)(0basedIndexOfDescription).Element(“Text”).Attribute(“v”).Value

for worlking second description:
XML_deserialized.Element("Doc").Elements("Description")(1).Element("Text").Attribute("v").Value

other options are

  • doing filtering with LINQ
  • Access with XPATH

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.