0
XmlElement xmlElementSAPD = xmlDocument.CreateElement("SAPD");
root.AppendChild(xmlElementSAPD);

xmlElementSAPD.AppendChild(XmlFunctions.GetXMLElement(xmlDocument, "smu", dr.GetString("sma").Trim()));

上記のc#コードは、以下のXMLを作成します。

<SAPD>
<smu>123</smu>
</SAPD>

上記のコードを変更して、取得できるようにするにはどうすればよいですか?

<ns0:SAPD>
<ns0:smu>123</ns0:smu>
</ns0:SAPD>

誰?どうすればms0:をxmlノードに追加できますか?

4

2 に答える 2

0

名前空間を xml ドキュメントに追加する必要があります。

アイデアを提供するために、以下をご覧ください

XmlDocument doc = new XmlDocument();  
XmlSchema schema = new XmlSchema();
schema.Namespaces.Add("ns0", "http://www.sample.com/file");
doc.Schemas.Add(schema);
于 2012-05-23T15:16:11.410 に答える
0

プレフィックス ns0 を名前空間にマップする必要があります。そうしないと、xml が無効になります。

ns0 がhttp://tempuri.org以下のコードにマップされていると仮定すると、次のコードを使用できます。

        XmlDocument doc = new XmlDocument();
        XmlElement sapd= doc.CreateElement("ns0","SAPD","http://tempuri.org");
        XmlElement smu = doc.CreateElement("ns0", "smu", "http://tempuri.org");
        smu.InnerText = "123";
        sapd.AppendChild(smu);
        doc.AppendChild(sapd);
        doc.InnerXml.ToString();
于 2012-05-23T15:28:19.877 に答える