我有3個實體作爲目標。任務和提醒。對於每個實體我有單獨的數據表。現在我想生成如下的xml用c動態生成xml#
<PDPData>
<Goal>
<TypeId>300</TypeId>
<NAME>Smart Goal #</NAME>
<Task>
<TypeId>11</TypeId>
<NAME>Task1</NAME>
</Task>
<Task>
<TypeId>12</TypeId>
<NAME>Task2</NAME>
</Task>
<Reminder>
<TypeId>11</TypeId>
<NAME>Reminder1</NAME>
</Reminder>
<Reminder>
<TypeId>12</TypeId>
<NAME>Reminder2</NAME>
</Reminder>
</Goal>
</PDPData>
我該如何實現這一點。我試着用下面的代碼,但其附加只有一個孩子,但我想追加和目標內
XmlElement hedder = docConfig.CreateElement("Goal");
docConfig.DocumentElement.PrependChild(hedder);
docConfig.ChildNodes.Item(0).AppendChild(hedder);
// Create <installationid> Node
XmlElement installationElement = docConfig.CreateElement("TypeId");
XmlText installationIdText = docConfig.CreateTextNode(dtGoals.Rows[goalCount]["TypeId"].ToString());
installationElement.AppendChild(installationIdText);
hedder.AppendChild(installationElement);
// Create <environment> Node
XmlElement environmentElement = docConfig.CreateElement("NAME");
XmlText environText = docConfig.CreateTextNode(dtGoals.Rows[goalCount]["Name"].ToString());
environmentElement.AppendChild(environText);
hedder.AppendChild(environmentElement);
您的第一個操作應該是搜索谷歌。這已被多次記錄! – 2013-04-11 06:51:00
我試過並在那裏搜索,但我無法找到正確的解決方案。 – nrsharma 2013-04-11 06:52:06
顯示給定XML的類定義和樣例數據。 – MarcinJuraszek 2013-04-11 06:53:38