0
下面的代码将创建而不是如何强制它成为<soap12:Body>
标记。Xml使用Soap12标签的自定义元素
XmlDocument xmlDoc = new XmlDocument();
XmlNode docNode = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);
xmlDoc.AppendChild(docNode);
XmlNode envelopeNode = xmlDoc.CreateElement("soap12", "Envelope", "http://www.w3.org/2003/05/soap-envelope");
xmlDoc.DocumentElement?.SetAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
xmlDoc.DocumentElement?.SetAttribute("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
XmlNode bodyNode = xmlDoc.CreateNode(XmlNodeType.Element, "soap12", "Body", null);
envelopeNode.AppendChild(bodyNode);
xmlDoc.AppendChild(envelopeNode);
将导致
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<Body />
</soap12:Envelope>
,而不是
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
</soap12:Body>
</soap12:Envelope>
如果想要格式化如下? <?xml version =“1.0”encoding =“utf-8”?>; ; Andrea soap12:Body> soap12:Envelope> –
superhuman1314