但是根元素本身正在使用“流”命名空间,这看起来很奇怪。这是有效的 XML 吗?
根元素本身使用stream
命名空间并不奇怪,但是......
Valid 必须与 XSD 相关,并且 XSD 必须与 XML 实例相关联。我看到命名空间指定的端点有一个 XSD: http://etherx.jabber.org/streams.xsd
。
建立关联的一种常见方法是使用xsi:schemaLocation
属性:
<stream:stream xmlns:stream='http://etherx.jabber.org/streams'
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://etherx.jabber.org/streams http://etherx.jabber.org/streams.xsd"
from='chat.facebook.com' id='1' version='1.0'>
</stream:stream>
验证然后可以找到要使用的 XML Schema,但是,有一个问题:
[Error] streams.xsd:23:21: cos-nonambig: WC["urn:ietf:params:xml:ns:xmpp-tls"] and WC[##other:"http://etherx.jabber.org/streams"] (or elements from their substitution group) violate "Unique Particle Attribution". During validation against this schema, ambiguity would be created for those two particles.
[Error] streams.xsd:74:21: cos-nonambig: "urn:ietf:params:xml:ns:xmpp-streams":text and WC[##other:"http://etherx.jabber.org/streams"] (or elements from their substitution group) violate "Unique Particle Attribution". During validation against this schema, ambiguity would be created for those two particles.
唯一粒子属性是 XSD 的必需约束。因此,要回答您的问题,我们不能说 XML 是有效的,因为我们没有有效的 XSD 来作为验证的基础。