- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我的工作是自动测试接受和返回 XML 的 API,因此我想尽可能多地将 API 的记录返回数据转换为模式。基于易用性和易学性,我选择 RelaxNG 来完成这项任务。
在我输入所有信息之前,这是一个问题:
是否可以描述“无序的元素集,具有相同的名称但不同的属性”?
这是一个示例对象,用于说明我在描述时遇到的问题:
<item>
<id>d395136e-d060-4a6e-887c-c0337dd7ad09</id>
<name>The item has a name</name>
<link rel="self" type="type1" href="url" />
<link rel="download" type="type2" href="url" />
<link rel="relatedData" type="type3" href="url" />
</item>
链接对象是我被挂断的地方。这是问题所在:
<interleave>
中结构。<link>
里面的元素<item>
,具有不同的属性集(即,<item>
必须具有“ self ”链接、“下载”链接和“相关数据”链接才有效)。 我试着这样描述架构:
<element name="item">
<interleave>
<element name="id"><text/></element>
<element name="name"><text/></element>
<ref name="selfLink"/>
<ref name="launchLink"/>
<ref name="thumbnailLink"/>
</interleave>
</element>
“链接”引用在别处定义如下:
<define name="selfLink">
<element name="link">
<attribute name="href"><text/></attribute>
<attribute name="rel"><value>self</value></attribute>
<attribute name="type"><value>type1</value></attribute>
</element>
</define>
解析器对此不满意 - 从 jing 我得到 error: the element "link" can occur in more than one operand of "interleave"
.我明白它的意思,但我希望它能够将“具有相同名称但属性不同的元素”作为唯一项来处理。
将链接引用从 interleave 中移出可以对其进行解析,但只要返回数据中的顺序发生变化,我将等待验证器崩溃。
任何想法,或者这是不可能的?我正在处理的 XML 是否存在固有问题,需要我将其中一些问题移至测试应用程序中的更高处理逻辑(在运行更通用的 XML 验证后手动检查每个链接类型?)
最佳答案
看起来您偶然发现了 restriction on interleave在 RELAX NG 中。我会尝试在 Schematron 中做到这一点,或者 RELAX NG 和 Schematron 的组合。
这是检查您的 <link>
的片段使用版本为 supported by Jing 的 Schematron 的元素:
<schema xmlns="http://www.ascc.net/xml/schematron">
<pattern name="link pattern">
<rule context="item">
<assert test='count(link) = 3'>There must be 3 link elements.</assert>
<assert test="count(link[@rel = 'self' and @type ='type1']) = 1">There must be 1 link element wwhere @rel='self' and @type='type1'.</assert>
<assert test="count(link[@rel = 'download' and @type ='type2']) = 1">There must be 1 link element where @rel='download' and @type='type2'.</assert>
<assert test="count(link[@rel = 'relatedData' and @type = 'type3']) = 1">There must be 1 link element where @rel='relatedData' and @type='type3'.</assert>
</rule>
</pattern>
</schema>
关于xml - relaxng 可以指定一组无序的同名但不同属性的元素吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11786196/
我正在尝试使用 RELAX-NG 为一些 XML 文档编写模式,当我将它与 jing 一起使用时,我收到一条我不理解的错误消息: C:\tmp\xml>java -jar jing.jar -c li
我的工作是自动测试接受和返回 XML 的 API,因此我想尽可能多地将 API 的记录返回数据转换为模式。基于易用性和易学性,我选择 RelaxNG 来完成这项任务。 在我输入所有信息之前,这是一个问
我有一个看起来很像这样的 RelaxNG 模式:
我正在使用 Jing API 进行 RelaxNG 和 xml 验证。我无法验证我指定的松弛字符串的长度。我用java编写了以下独立代码。在relaxng文件中,我已将minLength验证指定为3,
假设我有这个 XML: QEmu-fedora-i686 219200 hvm /usr/bin/qemu-system-x86_64
我已经开始使用 RelaxNG 来指定 XML 消息模式,并使用 PHP DOMDocument 来验证和解析传入的消息,但不知道如何定义文本节点以使其不能为空。示例架构:
使用 RelaxNG,我可以检查属性值在封闭元素中是否唯一吗? 例如,这个城堡应该验证: 但这不应该(在同一 room 中有重复的门):
为什么this XML从id="33426841601"到id="asdf"时changing the integer仍然有效? 我对 RELAXNG 完全陌生,但我希望 this part of t
我正在尝试使用 Nokogiri 验证 RelaxNG 紧凑语法文件。当我尝试这个时,Nokogiri 会抛出一个解析错误。我不知道它是否是 RelaxNG 文件,或者 Nokogiri 是否缺乏对紧
对于性能和准确性,您可以推荐哪些 XML 验证工具,这两者都是我们系统的关键问题?我们有以下要求: 不是 xmllint(见下文) 支持 RelaxNG 可以轻松地与 Perl 集成(这是可选的,但它
我有一个项目,我在其中使用 RelaxNG ( jing ) 来验证 xml。我喜欢 RelaxNG 的语法,但我使用的大多数工具都使用 XML 模式(实际上,我认为除了 jing 之外我没有其他工具
我正在为一个 XML 文件编写 RelaxNG Compact 模式,其中 的内容元素必须恰好是以下之一: 英语,要么 或 允许每人出现一次,或以任意顺序同时出现,但其中一个必须出现。 Wr
我想使用 Emacs 的 nxml-mode 编辑 XHTML 文件可以使用 rnc用于即时验证的模式。这些都内置于较新的 Emacs 版本中。 但是,我的 XHTML 文件包含来自另一个模式的元素。
事情是这样的:我(还)不希望通过 libvirt 在虚拟机中做一些操作。 我想要做的是采用 libvirt relaxng 模式并从中获取 java 类。这样我就可以生成一个代表虚拟机的 xml 配置
我的代码如下: try: schema = lxml.etree.RelaxNG(file=schema_file) schema.assertValid(etree) except
我想从 RelaxNG 架构中生成一个对象模型。 因此我想使用 RNGOM Object Model/Parser (主要是因为我找不到任何替代方案——尽管我什至不关心解析器编写/生成的语言)。现在我
我对在 C++ 中解析 xml 和一般的 xml 相当陌生。我正在尝试使用 libxml++ 库中的 SAXParser 解析我的文档,但是,我也希望它根据 relaxNG 模式验证我的文档。我发现
我想在客户端 JavaScript 中执行 RelaxNG(首选)或 XSD(如果必须)模式验证。有什么好的图书馆吗?谷歌发现jsrelaxngvalidator但我无法让它运行,而且似乎没有维护。目
看完this我一直在尝试实现一个由 RelaxNG XML validator (Jing) 使用的自定义数据类型。我已经通过命令行成功运行了 Jing 提供的示例实现(他们称之为 datatype-
我试图找到一种方法来查询 RNG 模式,同时避免重新发明轮子,以回答基本问题,例如:哪些元素是 XML 实例元素的有效子元素,它的属性可以/必须是什么,以及等等。 一个帖子 here提高了我对 Jin
我是一名优秀的程序员,十分优秀!