views:

40

answers:

2

Hello, 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.

A: 

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

w69rdy
Yes, I am using
jitm
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.
jitm
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.
w69rdy
I need a object that will be contain all data from this xml file namely: - arrays of element - arrays of element1 - arrays of element2That is all.
jitm
Have you got an object written already to deserialize the xml into?
w69rdy
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 .
jitm
A: 

I used xsd.exe

for to do it. Thanks.

jitm