代码如下
XmlDocument xmlDoc = new XmlDocument();
...
XmlElement parent = xmlDoc.CreateElement("Parent", "namespaceURI");
xmlDoc.AppendChild(parents);
XmlElement children = xmlDoc.CreateElement("Child");
parent.AppendChild(children);生成的结果是:
- <Parents xmlns="namespaceURI">
<Child xmlns="" />
</Parents>那如何生成:
- <Parents xmlns="namespaceURI">
<Child />
</Parents>
XmlDocument xmlDoc = new XmlDocument();
...
XmlElement parent = xmlDoc.CreateElement("Parent", "namespaceURI");
xmlDoc.AppendChild(parents);
XmlElement children = xmlDoc.CreateElement("Child");
parent.AppendChild(children);生成的结果是:
- <Parents xmlns="namespaceURI">
<Child xmlns="" />
</Parents>那如何生成:
- <Parents xmlns="namespaceURI">
<Child />
</Parents>
...
XmlElement parent = xmlDoc.CreateElement("Parent");
parent.SetAttribute("xmlns","namespaceURI");
xmlDoc.AppendChild(parents);
XmlElement children = xmlDoc.CreateElement("Child");
parent.AppendChild(children);