<Data ID="11">
<DataName ID="1122">
<DataValue ID="112233">xxxx</DataValue>
</DataName>
</Data>如何创建这样的Xml?
<DataName ID="1122">
<DataValue ID="112233">xxxx</DataValue>
</DataName>
</Data>如何创建这样的Xml?
解决方案 »
- How can I make a set of StackPanels look like several items.
- (结贴率100%)WinForm中tabcontrol控件如何添加背景???
- socket TCP通信错误,不知道错在哪??
- word操作问题 _____________
- TCP阻塞问题。握手之后,一端发,另一端不处理,会不会阻塞?
- 如何结束datagrid编辑?
- 所有button,textBox添加快捷键
- 关于CD和SPDIF的问题。
- 如何将一个字符串中指明的结构进行实例化
- 关于C++调用C# DLL库的问题
- C#怎么将一个xml的信息导入到另一个xml的某个节点中
- C#中,如何实现用户在textbox中输入数值格式为货币格式???
XmlElement root = xmlDoc.CreateElement("Data");
root.SetAttribute("ID", "11");
xmlDoc.AppendChild(root);
XmlElement dataName = xmlDoc.CreateElement("DataName");
dataName.SetAttribute("ID", "1122");
root.AppendChild(dataName);
XmlElement dataValue = xmlDoc.CreateElement("DataValue");
dataValue.SetAttribute("ID", "112233");
dataValue.InnerXml = "xxxx";
dataName.AppendChild(dataValue);
xmlDoc.Save(@"c:\test.xml");
执行完毕,到c:\下找test.xml
XDocument xdoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
XElement xele = new XElement("Data", new XAttribute("ID", "111"));
XElement xeleChild = new XElement("DataName", new XAttribute("ID", "222"));
XElement xeleChild2 = new XElement("DataValue", new XAttribute("ID", "333"),"XXX");
xeleChild.Add(xeleChild);
xele.Add(xeleChild);
xdoc.Add(xele);
xdoc.Save("xxx.xml");
XmlElement root=xmldoc.CreateElement("Data");
root.SetAttribute("ID","11");
xmldoc.AppendChild(root);
XmlElement childSec=xmldoc.CreateElement("DataName");
childSec.SetAttribute("ID","1122");
root.AppendChild(childSec);
XmlElement childThr=xmldoc.CreateElement("DataValue");
childThr.SetAttribute("ID","112233");
childThr.InnerText="xxxx";
childSec.AppendChild(childThr);
XElement Data=new XElement("Data",new XAttribute("ID",11));
XElement DataName=new XElement("DataName",new XAttribute("ID",1122));
XElement DataValue=new XElement("DataValue",new XAttribute("ID",112233),new XText("xxxx"));
Data.Add(DataName);
DataName.Add(DataValue);//save
Data.Save("路径");