askingPPl
askingPPl

Reputation: 263

how to delete Attribute in Xml

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>

Coding

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)

How to delete xmlns="" , I got try using RemoveAttribute and RemoveAttributeAt method but remove nothing. Isn't can remove it?

Upvotes: 2

Views: 804

Answers (2)

Tom W
Tom W

Reputation: 5403

This question I believe has an answer - because you're adding number without a namespace, it's assumed you don't intend it to be in the namespace of its parent. Because you don't specify a namespace, the rules of XML dictate that it has to be in the empty namespace, which the document specifies for you.

You should be able to fix it by explicitly specifying the same namespace as SubmitReq when you create it.

Upvotes: 2

ɐsɹǝʌ ǝɔıʌ
ɐsɹǝʌ ǝɔıʌ

Reputation: 4512

To remove an attribute, you can use the node.Attributes.RemoveNamedItem and pass the name of the attribute you want to remove as parameter and the attribute will be removed.

Upvotes: 0

Related Questions