Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XmlDocument.appendChild (et al.) is not closing tags immediately

Status
Not open for further replies.

stormbind

Technical User
Mar 6, 2003
1,165
GB
Where each small XmlDocument is..

Code:
<root>
<memberA></memberA>
<memberB></memberB>
</root>

Using the following .NET approach to copy and merge many small XmlDocuments into one new big XmlDocument..

Code:
XmlDocument big = new XmlDocument();
big.LoadXml("<example></example>");

List<XmlDocument> myXmlDocumentList = new List<XmlDocument>();
// lets assume we populated this list with lots of small XmlDocuments

foreach(XmlDocument small in myXmlDocumentList){
big.DocumentElement.AppendChild(big.ImportNode(small.DocumentElement, true));
}

Results in a big XmlDocument that looks like this..
Code:
<example>
<root>
<memberA></memberA>
<memberB></memberB>
<root>
<memberA></memberA>
<memberB><root>
<memberA></memberA>
<memberB></memberB>
</root></memberB>
</root>
</root>
</example>

Every element was appended and every tag closed, but the heirachy is a disaster.

What is a better way of copying small documents into a big document?

--Glen :)

Memoria mihi benigna erit qui eam perscribam
 
I bet the List (myXmlDocumentList) is wrongly established. It would have .Count=1 only and the sole item is mixed up. The line concerning the big should be working just fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top