<opentrans:ORDER version="2.1fd" type="standard"/>
</opentrans:OPENTRANS>
要生成上面的XML,用c#要怎么写?
求帮忙。
3 个解决方案
#1
XmlDocument.CreateElement("opentrans:OPENTRANS");
这样子不行吗? "opentrans:OPENTRANS"这个只会当做一个字符串来处理吧
#2
XmlDocument xml = new XmlDocument();
XmlDeclaration dec = xml.CreateXmlDeclaration("1.0", "utf-8", null);
xml.AppendChild(dec);
XmlElement root = xml.CreateElement("opentrans", "OPENTRANS", "http://www.opentrans.org/XMLSchema/2.1fd");
xml.AppendChild(root);
XmlElement element = xml.CreateElement("opentrans:ORDER", "http://www.opentrans.org/XMLSchema/2.1fd");
element.SetAttribute("version", "2.1fd");
element.SetAttribute("type", "standard");
root.AppendChild(element);
xml.Save(@"E:\1.xml");
<?xml version="1.0" encoding="utf-8"?>
<opentrans:OPENTRANS xmlns:opentrans="http://www.opentrans.org/XMLSchema/2.1fd">
<opentrans:ORDER version="2.1fd" type="standard" />
</opentrans:OPENTRANS>
#3
++
其实直接拼就OK了。
#1
XmlDocument.CreateElement("opentrans:OPENTRANS");
这样子不行吗? "opentrans:OPENTRANS"这个只会当做一个字符串来处理吧
#2
XmlDocument xml = new XmlDocument();
XmlDeclaration dec = xml.CreateXmlDeclaration("1.0", "utf-8", null);
xml.AppendChild(dec);
XmlElement root = xml.CreateElement("opentrans", "OPENTRANS", "http://www.opentrans.org/XMLSchema/2.1fd");
xml.AppendChild(root);
XmlElement element = xml.CreateElement("opentrans:ORDER", "http://www.opentrans.org/XMLSchema/2.1fd");
element.SetAttribute("version", "2.1fd");
element.SetAttribute("type", "standard");
root.AppendChild(element);
xml.Save(@"E:\1.xml");
<?xml version="1.0" encoding="utf-8"?>
<opentrans:OPENTRANS xmlns:opentrans="http://www.opentrans.org/XMLSchema/2.1fd">
<opentrans:ORDER version="2.1fd" type="standard" />
</opentrans:OPENTRANS>
#3
++
其实直接拼就OK了。