Xml struture
<soap-env:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<mm7:id xmlns:mm7="http://schemas.xmlsoap.org/soap/envelope/" mustUnderstand="1">1234</mm7:id>
</soapenv:Header>
<soap-env:Body>
<SubmitReq>
<number xmlns="">5674</number>
</SubmitReq>
</soap-env:Body>
</soapenv:Envelope>
编码
Dim bodychild As XmlElement = _xmlRequest.CreateElement("SubmitReq", "http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-2")
soapBody.AppendChild(bodychild)
Dim numberAs XmlElement = _xmlRequest.CreateElement("number")
number.InnerText = "5674"
bodychild.AppendChild(number)
如何删除xmlns =“”,我尝试使用RemoveAttribute和RemoveAttributeAt方法,但什么也没删除。是不是可以删除它?
答案 0 :(得分:2)
This question我相信有一个答案 - 因为您在没有命名空间的情况下添加number
,假设您不打算将其置于其名称空间中家长。因为您没有指定命名空间,所以XML规则规定它必须位于文档为您指定的空命名空间中。
您应该能够通过在创建时明确指定与SubmitReq
相同的命名空间来修复它。
答案 1 :(得分:0)
要删除属性,您可以使用node.Attributes.RemoveNamedItem
并将要删除的属性名称作为参数传递,该属性将被删除。