XmlDocument pXmlDocument = new XmlDocument();
XmlDeclaration pXmlDeclaration = pXmlDocument.CreateXmlDeclaration("1.0", "utf-8", null);
pXmlDocument.AppendChild(pXmlDeclaration);
//加入一个根元素
XmlElement pElement = pXmlDocument.CreateElement("", "num", "");
pXmlDocument.AppendChild(pElement);
XmlNode pXmlRootNode = pXmlDocument.SelectSingleNode("num");//拿到根元素
XmlElement pXmlElement = pXmlDocument.CreateElement("job" + job);//添加要素
XmlElement px = pXmlDocument.CreateElement("x");
XmlElement py = pXmlDocument.CreateElement("y");
XmlElement pz = pXmlDocument.CreateElement("z");
px.InnerText = x.ToString();
py.InnerText = y.ToString();
pz.InnerText = z.ToString();
pXmlElement.AppendChild(px);
pXmlElement.AppendChild(py);
pXmlElement.AppendChild(pz);
pXmlRootNode.AppendChild(pXmlElement);
pXmlDocument.Save(xmlPath);
创建xml
最新推荐文章于 2024-07-16 19:26:54 发布