作者party100046 (陳靖仇)
看板C_Sharp
標題[問題] Xml節點問題
時間Tue Jul 27 19:56:45 2010
我的問題是這樣的
我想產生一個Xml檔案,而檔案的內容如下
<Battle>
<modle_stuff_growth_rule_list>
<stuff_growth_rule>
</stuff_growth_rule>
</modle_stuff_growth_rule_list>
</Battle>
我想產生一個如上所描述的xml格式
程式碼如下:
private void SaveQualityxml(string filename)
{
XmlDocument xmlDoc;
XmlElement rootNode;
xmlDoc = new XmlDocument();
XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0",
"utf-8", null);
xmlDoc.InsertBefore(xmlDeclaration, xmlDoc.DocumentElement);
rootNode = xmlDoc.CreateElement("Battle");
xmlDoc.AppendChild(rootNode);
XmlElement QualityNode = xmlDoc.CreateElement("Stuff_Name");
rootNode.AppendChild(QualityNode);
XmlText QualityValue = xmlDoc.CreateTextNode(QualityName.Text);
QualityNode.AppendChild(QualityValue);
xmlDoc.Save(filename);
}
這段程式碼所產生出來的Xml結變成
<Battle>
<modle_stuff_growth_rule_list>
<Stuff_Name>
</Stuff_Name>
</modle_stuff_growth_rule_list>
</Battle>
我想問一下,要如何改成一開始所描述的Xml格式?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 123.204.17.136
※ 編輯: party100046 來自: 123.204.17.136 (07/27 19:57)
→ retsamsu:不就把Stuff_Name換成stuff_growth_rule就好了? 07/27 20:30
→ party100046:寫出來了,只是階層的觀念:D 07/27 21:48