2

There is next xml file:

<element Name="root">
    <SubFields>
        <element Name="subroot">
            <SubFields>
                <element1 Name="element1" customatt1 = "12313" customatt2 = "asdfasfadsfasd">
                    <subelement Name="subelement" />
                </element1>
                <element1 Name="element11" customatt1 = "12313" customatt2 = "asdfasfadsfasd">
                    <subelement Name="subelement" />
                </element1>
                <element1 Name="element111" customatt1 = "12313" customatt2 = "asdfasfadsfasd">
                    <subelement Name="subelement" />
                </element1>
                <element2 Name="element2" path = "asdfdsf" widget="asdasdasd">
                    <subelement Name="subelement" />
                </element2>
                <element2 Name="element22" path = "asdfdsf" widget="asdasdasd">
                    <subelement Name="subelement" />
                </element2>
                <element2 Name="element222" path = "asdfdsf" widget="asdasdasd">
                    <subelement Name="subelement" />
                </element2>
            </SubFields>
        </element>
    </SubFields>
</element>

I mapped the array of elements as [XmlArray("SubFields")] where SubFields is root of arrays and Question: How to map differences types of elements in object ? And I can have a lot of subroot -s elements.

2 Answers 2

1

I used xsd.exe to do it.

Sign up to request clarification or add additional context in comments.

Comments

0

Use the XMLSerializer class. Near the bottom theres a section about using Property attributes to map the object to the xml elements

5 Comments

The main idea of question how to map differences element in xml sequence in object, and under "map" I understood use of c# attributes like [XMLArray] and so on.
Do you need the XMl in that exact format? If not it's usually a lot easier to create and populate the object that you can then serialize and deserialize to xml rather than the other way round.
I need a object that will be contain all data from this xml file namely: - arrays of element - arrays of element1 - arrays of element2 That is all.
Have you got an object written already to deserialize the xml into?
I need to write this object, I have written objects only for top part of xml: <element Name="root"> <SubFields> <element Name="subroot"> </element> </SubFields> </element> Currently I need to write for the another elements .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.