J'ai un nœud xml que j'ai extrait et j'utilise XmlWriter pour créer le fichier Xml correspondant.
Le XmlNode doit aller à l'intérieur mais je ne savais pas comment utiliser le XmlNode pour créer les éléments à l'intérieur.
Format Xml comme ci-dessous
<?xml version="1.0" encoding="UTF-8"?>
<tasks>
<task Id="113" Date="2013-03-12T13:55:09" NodeId="1842" TotalWords="11">
</task>
</tasks>
Codes XmlWriter
using (XmlWriter writer = XmlWriter.Create(MapPath(xmlFilePath)))
{
writer.WriteStartDocument();
writer.WriteStartElement("Tasks");
writer.WriteStartElement("Task");
writer.WriteAttributeString("Id", t.Id.ToString());
writer.WriteAttributeString("NodeId", t.Node.Id.ToString());
// The XmlNode needs to be inside here //
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndDocument();
}
Détails du XmlNode que j'ai retiré
<Page id="1842" parentID="1840" level="5" writerID="14" creatorID="14" nodeType="1051" template="1839" sortOrder="0" createDate="2013-03-11T14:53:47" updateDate="2013-03-12T14:03:55" nodeName="Ujian sub-halaman" urlName="ujian-sub-halaman" writerName="John John" creatorName="John John" path="-1,1057,1631,1156,1840,1842" isDoc="">
<pageContent />
<heroHeaderImage />
<topModule>-1</topModule>
<bottomModule>-1</bottomModule>
<rHTopModule />
<headerQuickLinks>
<data />
</headerQuickLinks>
<rHBottomModule>-1</rHBottomModule>
<pageTitle>Ujian sub-halaman</pageTitle>
<umbracoNaviHide>0</umbracoNaviHide>
<pageHeader><![CDATA[Test sub-page]]></pageHeader>
<showAddThis>0</showAddThis>
<alternativeTitle>Test sub-page</alternativeTitle>
<smallPrint>0</smallPrint>
<pageImage />
<siteName />
<metaDescription />
<metaKeywords />
<metaCopyright />
<defaultEmail />
<googleUrchin />
<facebook />
<googlePlus />
<linkedIn />
<twitter />
<youtube />
</Page>