问题
I´ve an xml instance similar to this:
<outerElementList>
<outerElement>
<outerID>1</outerID>
<innerElementList>
<innerElement>
<innerID>10</innerID>
</innerElement>
<innerElement>
<innerID>20</innerID>
</innerElement>
</innerElementList>
</outerElement>
<outerElement>
<outerID>2</outerID>
<innerElementList>
<innerElement>
<innerID>30</innerID>
</innerElement>
<innerElement>
<innerID>40</innerID>
</innerElement>
</innerElementList>
</outerElement>
</outerElementList>
And I need to end up with this structure:
<ElementList>
<Element>
<ID>1</ID>
</Element>
<Element>
<ID>2</ID>
</Element>
<Element>
<ID>10</ID>
</Element>
<Element>
<ID>20</ID>
</Element>
<Element>
<ID>30</ID>
</Element>
<Element>
<ID>40</ID>
</Element>
</ElementList>
I realize that I need to use a looping functoid, but I just cant seem to get it right.
Also does anyone know of a good tutorial to do these maps i C#?
回答1:
You'll want to map it like this:
Using this input:
<ns0:outerElementList xmlns:ns0="http://BizTalk_Server_Project1.Schema1">
<outerElement>
<outerID>1</outerID>
<innerElementList>
<innerElement>
<innerID>10</innerID>
</innerElement>
<innerElement>
<innerID>20</innerID>
</innerElement>
</innerElementList>
</outerElement>
<outerElement>
<outerID>2</outerID>
<innerElementList>
<innerElement>
<innerID>30</innerID>
</innerElement>
<innerElement>
<innerID>40</innerID>
</innerElement>
</innerElementList>
</outerElement>
</ns0:outerElementList>
I got this output:
<ns0:ElementList xmlns:ns0="http://BizTalk_Server_Project1.Schema2">
<Element>
<ID>1</ID>
</Element>
<Element>
<ID>2</ID>
</Element>
<Element>
<ID>10</ID>
</Element>
<Element>
<ID>20</ID>
</Element>
<Element>
<ID>30</ID>
</Element>
<Element>
<ID>40</ID>
</Element>
</ns0:ElementList>
来源:https://stackoverflow.com/questions/22035260/flattening-repeating-structure-in-biztalk