xml - 根元素中的命名空间定义也是命名空间 - 有效的 XML?

标签 xml xmpp dart xml-namespaces

我的客户正在与 Facebook chat server 进行友好的 XMPP 对话并接收如下所示的 XML 片段:

<stream:stream xmlns:stream='http://etherx.jabber.org/streams' from='chat.facebook.com' id='1' version='1.0' >
</stream:stream>

因此根元素上有一个命名空间定义“stream”。到目前为止一切顺利。

但是根元素本身正在使用“stream”命名空间,这看起来很奇怪。这是有效的 XML 吗?

我正在使用的 XML 库 ( dart-xml ) 提示它,我想知道是否正确,或者该库是否有 bug .

最佳答案

But the root element itself is using the "stream" namespace, which seems odd. Is this valid 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 架构,但是有一个问题:

[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.

Unique Particle Attribution是 XSD 的必需约束。因此,为了回答您的问题,我们不能说 XML 是有效的,因为我们没有有效的 XSD 作为验证的基础。

关于xml - 根元素中的命名空间定义也是命名空间 - 有效的 XML?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19473373/

相关文章:

xml - XSLT - 属性的出现

java - 中心裁剪在 gridlayoutmanager Android 中不起作用

使用 Google App Engine 的 Facebook 聊天机器人

android - 当我运行我的 flutter 应用程序时显示白色空白屏幕

c# - XPATH 查询以从存储在 SQL Server 数据库列中的 XML 中获取数据

c# - 在 Excel 文件中存储 XML 数据的最佳方式是什么

xmpp - 如何在 ejabberd/XMPP 中获得发送/接收消息的确认?

当应用程序被用户或 Android 操作系统停止或终止时,Android 应用程序未收到 Firebase 通知

dart - polymer -如何从Paper-Input获取ID?

dart - Dart:以String作为参数的函数作为回调中的参数