- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
...或者为什么这些文件在 Visual Studio 2010 中验证而不是 xmllint1?
我目前正在处理一个已发布的 xml 架构,其中原作者的习惯是将架构分解为多个 .xsd 文件,但其中一些架构文件具有相同的 targetNamespace
。这真的是“允许的”吗?
示例(极度简化):
File targetNamespace Contents
------------------------------------------------------------
b1.xsd uri:tempuri.org:b complex type "fooType"
b2.xsd uri:tempuri.org:b simple type "barType"
a.xsd uri:tempuri.org:a imports b1.xsd and b2.xsd
definition of root element "foo", that
extends "b:fooType" with an attribute
of "b:barType"
(下面是完整的文件内容。)
然后我有一个 xml 文件,data.xml
,内容如下:
<?xml version="1.0"?>
<foo bar="1" xmlns="uri:tempuri.org:a" xmlns:xs="http://www.w3.org/2001/XMLSchema" />
很长一段时间以来,我一直相信所有这些都是正确的,因为 Visual Studio 显然允许这种架构样式。然而,今天我决定设置一个命令行实用程序来验证 xml 文件,我选择了 xmllint
。
当我运行 xmllint --schema a.xsd data.xml
时,我看到了这个警告:
a.xsd:4: element import: Schemas parser warning : Element '{http://www.w3.org/2001/XMLSchema}import': Skipping import of schema located at 'b2.xsd' for the namespace 'uri:tempuri.org:b', since this namespace was already imported with the schema located at 'b1.xsd'.
b2.xsd
的导入被跳过的事实显然导致了这个错误:
a.xsd:9: element attribute: Schemas parser error : attribute decl. 'bar', attribute 'type': The QName value '{uri:tempuri.org:b}barType' does not resolve to a(n) simple type definition.
如果 xmllint
是正确的,那么我正在处理的已发布规范中就会有错误。 有吗? Visual Studio 会出错。 是吗?
我确实意识到 xs:import
和 xs:include
之间的区别。现在,我只是不明白 xs:include
如何解决问题,因为:
b1.xsd
和b2.xsd
有相同的targetNamespace
targetNamespace
和 a.xsd
上都不同这是原始模式规范中的缺陷吗?我开始认为第三点至关重要。他们彼此不了解这一事实是否应该导致将他们放在不同的命名空间中?
b1.xsd:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="uri:tempuri.org:b" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="fooType" />
</xs:schema>
b2.xsd:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="uri:tempuri.org:b" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="barType">
<xs:restriction base="xs:integer" />
</xs:simpleType>
</xs:schema>
a.xsd:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="uri:tempuri.org:a" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:b="uri:tempuri.org:b">
<xs:import namespace="uri:tempuri.org:b" schemaLocation="b1.xsd" />
<xs:import namespace="uri:tempuri.org:b" schemaLocation="b2.xsd" />
<xs:element name="foo">
<xs:complexType>
<xs:complexContent>
<xs:extension base="b:fooType">
<xs:attribute name="bar" type="b:barType" />
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
</xs:schema>
注释:
1) 我正在使用 libxml2/xmllint 的 Windows 端口在 www.zlatkovic.com 找到.
最佳答案
这里问题的症结在于,当您有两个不同的 <import>
时,这意味着什么?元素,当它们都引用相同的命名空间时。
当您考虑 schemaLocation
时,它有助于阐明含义<import>
的属性完全是可选的。当您省略它时,您只是在说“我想将命名空间 XYZ 的模式导入到这个 模式中”。 schemaLocation
只是关于在哪里可以找到其他模式的定义的提示。
<import>
的准确含义当您阅读 W3C 规范时有点模糊,可能是故意的。结果,解释各不相同。
一些 XML 处理器容忍多个 <import>
对于相同的命名空间,并基本上合并所有 schemaLocation
成一个单一的目标。
其他处理器更严格,决定只有一个<import>
每个目标 namespace 均有效。我认为这是更正确的,当你考虑到 schemaLocation
是可选的。
除了你给的VS和xmllint的例子,Xerces-J也是超严格的,忽略后面的<import>
对于相同的目标 namespace ,给出与 xmllint 相同的错误。另一方面,XML Spy 更为宽松(但是 XML Spy 的验证是出了名的不稳定)
为了安全起见,您不应该有这些多重导入。一个给定的命名空间应该有一个单一的“主”文档,它又有一个 <include>
对于每个子文档。这个主人通常是高度虚假的,只充当一个容器。对于这些子文档。
据我所知,这通常包含 XML 模式在最大工具兼容性方面的“最佳实践”,但有些人会争辩说这是一种摆脱优雅模式设计的技巧。
嗯。
关于xml - 一个 xml 命名空间等于一个且只有一个模式文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4998063/
对此感到疯狂,真的缺少一些东西。 我有webpack 4.6.0,webpack-cli ^ 2.1.2,所以是最新的。 在文档(https://webpack.js.org/concepts/mod
object Host "os.google.com" { import "windows" address = "linux.google.com" groups = ["linux"] } obj
每当我安装我的应用程序时,我都可以将数据库从 Assets 文件夹复制到 /data/data/packagename/databases/ .到此为止,应用程序工作得很好。 但 10 或 15 秒后
我在 cc 模式缓冲区中使用 hideshow.el 来折叠我不查看的文件部分。 如果能够在 XML 文档中做到这一点就好了。我使用 emacs 22.2.1 和内置的 sgml-mode 进行 xm
已结束。此问题不符合 Stack Overflow guidelines .它目前不接受答案。 我们不允许提出有关书籍、工具、软件库等方面的建议的问题。您可以编辑问题,以便用事实和引用来回答它。 关闭
根据java: public Scanner useDelimiter(String pattern) Sets this scanner's delimiting pattern to a patt
我读过一些关于 PRG 模式以及它如何防止用户重新提交表单的文章。比如this post有一张不错的图: 我能理解为什么在收到 2xx 后用户刷新页面时不会发生表单提交。但我仍然想知道: (1) 如果
看看下面的图片,您可能会清楚地看到这一点。 那么如何在带有其他一些 View 的简单屏幕中实现没有任何弹出/对话框/模式的微调器日期选择器? 我在整个网络上进行了谷歌搜索,但没有找到与之相关的任何合适
我不知道该怎么做,我一直遇到问题。 以下是代码: rows = int(input()) for i in range(1,rows): for j in range(1,i+1):
我想为重写创建一个正则表达式。 将所有请求重写为 index.php(不需要匹配),它不是以/api 开头,或者不是以('.html',或'.js'或'.css'或'.png'结束) 我的例子还是这样
MVC模式代表 Model-View-Controller(模型-视图-控制器) 模式 MVC模式用于应用程序的分层开发 Model(模型) - 模型代表一个存取数据的对象或 JAVA PO
我想为组织模式创建一个 RDF 模式世界。您可能知道,组织模式文档基于层次结构大纲,其中标题是主要的分组实体。 * March auxiliary :PROPERTIES: :HLEVEL: 1 :E
我正在编写一个可以从文件中读取 JSON 数据的软件。该文件包含“person”——一个值为对象数组的对象。我打算使用 JSON 模式验证库来验证内容,而不是自己编写代码。符合代表以下数据的 JSON
假设我有 4 张 table 人 公司 团体 和 账单 现在bills/persons和bills/companys和bills/groups之间是多对多的关系。 我看到了 4 种可能的 sql 模式
假设您有这样的文档: doc1: id:1 text: ... references: Journal1, 2013, pag 123 references: Journal2, 2014,
我有这个架构。它检查评论,目前工作正常。 var schema = { id: '', type: 'object', additionalProperties: false, pro
这可能很简单,但有人可以解释为什么以下模式匹配不明智吗?它说其他规则,例如1, 0, _ 永远不会匹配。 let matchTest(n : int) = let ran = new Rand
我有以下选择序列作为 XML 模式的一部分。理想情况下,我想要一个序列: 来自 my:namespace 的元素必须严格解析。 来自任何其他命名空间的元素,不包括 ##targetNamespace和
我希望编写一个 json 模式来涵盖这个(简化的)示例 { "errorMessage": "", "nbRunningQueries": 0, "isError": Fals
首先,我是 f# 的新手,所以也许答案很明显,但我没有看到。所以我有一些带有 id 和值的元组。我知道我正在寻找的 id,我想从我传入的三个元组中选择正确的元组。我打算用两个 match 语句来做到这
我是一名优秀的程序员,十分优秀!