将XML名称空间前缀替换为完整的名称空间URI值?

时间:2018-10-19 19:17:06

标签: xml soap xml-namespaces

要详细说明这个问题,可以将名称空间定义替换为定义吗?

这仍然是格式正确的XML吗?它们是上下文中的“相同”消息,还是第二条仍然格式良好的SOAP XML消息,就像原始消息一样。

例如, 这是来自Oracle示例的格式正确的SOAP XML消息。然后,我将对其进行复制,但将SOAP-ENV属性替换为其定义:

<?xml version="1.0" encoding="utf-8" ?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
    <SOAP-ENV:Fault>
        <faultcode>SOAP-ENV:Client</faultcode>
        <faultstring>Message does not have necessary info</faultstring>
        <faultactor>http://gizmos.com/order</faultactor>
        <detail>
        <PO:order xmlns:PO="http://gizmos.com/orders/">
        Quantity element does not have a value</PO:order>
        <PO:confirmation xmlns:PO="http://gizmos.com/confirm">
        Incomplete address: no zip code</PO:confirmation>
        </detail>
    </SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

因此,由引用的定义SOAP-ENV定义的"http://schemas.xmlsoap.org/soap/envelope/"被替换。

<?xml version="1.0" encoding="utf-8" ?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<http://schemas.xmlsoap.org/soap/envelope/:Header/>
<http://schemas.xmlsoap.org/soap/envelope/:Body>
    <http://schemas.xmlsoap.org/soap/envelope/:Fault>
        <faultcode>SOAP-ENV:Client</faultcode>
        <faultstring>Message does not have necessary info</faultstring>
        <faultactor>http://gizmos.com/order</faultactor>
        <detail>
        <PO:order xmlns:PO="http://gizmos.com/orders/">
        Quantity element does not have a value</PO:order>
        <PO:confirmation xmlns:PO="http://gizmos.com/confirm">
        Incomplete address: no zip code</PO:confirmation>
        </detail>
    </http://schemas.xmlsoap.org/soap/envelope/:Fault>
</http://schemas.xmlsoap.org/soap/envelope/:Body>
</http://schemas.xmlsoap.org/soap/envelope/:Envelope>

1 个答案:

答案 0 :(得分:2)

否,您建议的用名称空间URI替换名称空间前缀的语法不是格式正确的XML。不过某些软件支持某些功能:

<{http://schemas.xmlsoap.org/soap/envelope/}Envelope />

通常称为Clark Notation