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