作者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)
1F:→ retsamsu:不就把Stuff_Name换成stuff_growth_rule就好了? 07/27 20:30
2F:→ party100046:写出来了,只是阶层的观念:D 07/27 21:48