0

私がこのようなことをすると:

System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
XmlElement e = xmlDoc.CreateElement("ShipmentReceiptNotification");
e.SetAttribute("xmlns", "urn:rosettanet:specification:interchange:ShipmentReceiptNotification:xsd:schema:02.02");
e.SetAttribute("xmlns:ssdh", "urn:rosettanet:specification:domain:Procurement:AccountClassification:xsd:codelist:01.03");
XmlNode ShipmentReceiptNotification0Node = e;

ShipmentReceiptNotification0Node.InnerText = String.Empty;
xmlDoc.AppendChild(ShipmentReceiptNotification0Node);
XmlNode DocumentHeader1Node = xmlDoc.CreateElement("ssdh:DocumentHeader");
ShipmentReceiptNotification0Node.AppendChild(DocumentHeader1Node);

2 番目のノードのプレフィックスは表示されssdhず、表示されるだけDocumentHeaderになります。どうすればこれを修正できますか?

4

1 に答える 1

1

次のように作成する必要があります。

XmlNode DocumentHeader1Node = xmlDoc.CreateElement("ssdh", "DocumentHeader", "urn:rosettanet:specification:domain:Procurement:AccountClassification:xsd:codelist:01.03");

重要なのはXmlDocument、どの名前空間プレフィックス(最初の引数)がどの名前空間URI(3番目の引数)に対応するかを知る必要があるということです。少し直感に反しますが、これが機能する方法です。

ShipmentReceiptNotification0Node.InnerText = String.Empty;また、この行は役に立たないことに注意してください。省略しても安全です。要素はデフォルトで空です。

于 2013-03-08T18:51:46.837 に答える