Namespace in XML element value?

2020-04-18 06:46发布

I recently stumbled across this:

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing">
    <s:Header>
        <a:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe</a:Action>
        <a:MessageID>uuid:21859bf9-6193-4c8a-ad50-d082e6d296ab</a:MessageID>
        <a:ReplyTo>
            <a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address>
        </a:ReplyTo>
        <a:To s:mustUnderstand="1">urn:schemas-xmlsoap-org:ws:2005:04:discovery</a:To>
    </s:Header>
    <s:Body>
        <Probe xmlns="http://schemas.xmlsoap.org/ws/2005/04/discovery">
            <d:Types xmlns:d="http://schemas.xmlsoap.org/ws/2005/04/discovery" xmlns:dp0="http://www.onvif.org/ver10/network/wsdl">dp0:NetworkVideoTransmitter</d:Types>
        </Probe>
    </s:Body>
</s:Envelope>

One thing that perplexes me is the line:-

<d:Types xmlns:d="http://schemas.xmlsoap.org/ws/2005/04/discovery" xmlns:dp0="http://www.onvif.org/ver10/network/wsdl">dp0:NetworkVideoTransmitter</d:Types>

The namespace dp0 is actually used in the element value, does that mean anything at all?

1条回答
够拽才男人
2楼-- · 2020-04-18 06:53

At the XML level, no, a namespace prefix has no meaning within content -- namespaces and namespace prefixes are purely markup-level constructs.

Furthermore, any application that uses namespace prefixes in the content will have to take care to only care about the namespace to which the prefix is bound, not the prefix itself.

Finally, since the namespace prefix (dp0, here) is insignificant other than via through its association with a namespace value (http://www.onvif.org/ver10/network/wsdl), the numeric 0 suffix of the namespace prefix is also insignificant. Typically, it's just a counter appended programmatically to ensure that the namespace prefix is unique.

查看更多
登录 后发表回答