c# - populating xml template at run time from object collection at runtime -


i have xml template having header , details section within it. have populate data xml template @ run time object collection. details part repeating adding details part xml document in foreach loop. using xmldocument read xmldocument occupies more memory , makes process slow on increasing size of xml file. please suggest me best approach.

tempalte example

<document>   <header>     <orgname></orgname>     <orgaddress></orgaddress>   </header>   <detail>     <empid> </empid>     <empname></empname>     <address>       <stree1></stree1>       <stree2></stree2>       <pin></pin>       <city></city>     </address>   <detail> </document> 

expected result

<document>   <header>    <orgname>abc</orgname>    <orgaddress>asd dfs 999 dfsd</orgaddress>   </header>   <detail>    <empid>100 </empid>    <empname>sham</empname>    <address>        <stree1>church street</stree1>        <stree2>fgdf</stree2>        <pin>5472</pin>        <city>huston</city>    </address> <detail> <detail>   <empid>112 </empid>   <empname>tomi</empname>   <address>       <stree1>fsdf</stree1>       <stree2>fgdf</stree2>       <pin>3455</pin>       <city>huston</city>   </address> <detail> <detail>  <empid>120 </empid>   <empname>ghansham</empname>   <address>       <stree1>sfssdf</stree1>       <stree2>fgdf</stree2>       <pin>6574</pin>       <city>huston</city>   </address> <detail> </document> 

if want memory efficient way write xml, should use xmlwriter class.

http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.aspx

here example, using of xml:

using(xmlwriter writer = xmlwriter.create("output.xml")) {     writer.writestartelement("document");     writer.writestartelement("header");      writer.writestartelement("orgname");     writer.writestring("abc");     writer.writeendelement();      writer.writestartelement("orgaddress");     writer.writestring("asd dfs 999 dfsd");     writer.writeendelement();      // end header     writer.writeendelement();      writer.writestartelement("detail");      writer.writestartelement("empid");     writer.writestring("100");     writer.writeendelement();      // end detail     writer.writeendelement();      // end document     writer.writeendelement(); } 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -