VB.NET将命名空间添加到现有的

时间:2018-04-09 21:25:09

标签: .net xml

我希望将其作为XML:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:sear="http://eur-lex.europa.eu/search">
<soap:Header>
</soap:Header>
</soap:Envelope>

我的代码:

Dim D As New Xml.XmlDocument
Dim soapEnvelope As Xml.XmlElement = D.AppendChild(D.CreateElement("soap", "Envelope", "http://www.w3.org/2003/05/soap-envelope"))
soapEnvelope.SetAttribute("xmlns:sear", "http://eur-lex.europa.eu/search")
Dim soapHeader As Xml.XmlElement = soapEnvelope.AppendChild(D.CreateElement("soap:Header"))

但是Header Element没有“soap”前缀。

不是:

<soap:Header>

我该如何解决?

1 个答案:

答案 0 :(得分:0)

不是创建名为soap:Header的元素,而是执行此操作:

Dim soapHeader As Xml.XmlElement = 
    soapEnvelope.AppendChild(
        D.CreateElement("soap", "Header", "http://www.w3.org/2003/05/soap-envelope"))

您也可以使用XNamespace解释in the documentation,甚至可以使用Xml文字。

相关问题