- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
0"always true,,即使字符串不匹配-6ren"> 0"always true,,即使字符串不匹配-我想使用 XSD1.1 断言功能来验证内容级别的元素。(更准确地说,我想检查以 XML 表示的 EDIFACT 中是否存在内容组合,但这不是重点...) 为了测试我的 XPath,我构建了以下小型测试-6ren">
我想使用 XSD1.1 断言功能来验证内容级别的元素。(更准确地说,我想检查以 XML 表示的 EDIFACT 中是否存在内容组合,但这不是重点...)
为了测试我的 XPath,我构建了以下小型测试场景:
XML
<root>
<group>
<elem1>test1</elem1>
<elem2>test2</elem2>
</group>
<group>
<elem1>something1</elem1>
<elem2>something2</elem2>
</group>
<group>
<elem1>other1</elem1>
<elem2>other2</elem2>
</group>
</root>
要求是:我想检查,我有 test1 + test2 字符串的组合,以及 something1 和 something2 字符串的组合。可能有像 other1 + other2 组这样的组,可以有,但我不在乎。这里三组的顺序应该也没有影响。
我要测试的 XSD 是:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="root">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="group" minOccurs="1" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="elem1" minOccurs="1">
</xsd:element>
<xsd:element name="elem2" minOccurs="1">
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:assert test="(count(./group/elem1/text() = 'test1') > 0
and count(./group/elem2/text() = 'test2') > 0)
and (count(./group/elem1/text() = 'something1') > 0
and count(./group/elem2/text() = 'something2') > 0)"/>
</xsd:complexType>
</xsd:element>
</xsd:schema>
有趣的是:
(count(./group/elem1/text() = 'test1') > 0
and count(./group/elem2/text() = 'test2') > 0)
and (count(./group/elem1/text() = 'something1') > 0
and count(./group/elem2/text() = 'something2') > 0)
或将其分解:
count(./group/elem1/text() = 'test1') > 0
我的问题是:即使字符串不匹配,表达式(更具体地说是计数)返回 true。比方说,我针对“test1”进行测试,但我的字符串是“test”:
./group/elem1/text() = 'test1'
在其中 self 运作。它正确地返回 true 或 false。但是对它使用计数是行不通的。 (似乎总是返回 true)
我假设,在这里计数不是正确的解决方案,问题是,我不想测试每个组“它是完全正确的”,但毕竟所有组“这个和这个特定的组合至少出现一次”组的所有重复。
我正在 Saxon 9 EE 上对此进行测试,但 XPath 在其他 XPath 实现上也具有相同的行为。
如有任何帮助,我们将不胜感激。
谢谢,电子
编辑:
在 Mads Hansen 和 Michael Kay(谢谢!)的帮助下实现这一目标后,我还有最后一个障碍要跨越:
考虑这种情况:
<root>
<group>
<elem1>test1</elem1>
<elem2>WRONG</elem2>
</group>
<group>
<elem1>WRONG</elem1>
<elem2>test2</elem2>
</group>
</root>
用这个 XPath
计数(组[elem1/text() = 'test1' and elem2/text() = 'test2']) > 0)
这现在导致上面的示例无效(正如我所希望的那样),而我已经验证了上面的原始 XPath,因为它没有在 .
最佳答案
您需要调整 XPath 以过滤您要查找的项目,然后统计剩余的项目。您当前的表达式正在评估 group/elem1/text()
节点中的任何一个是否等于 test1
,这将是 true()
或 false()
,然后计算 bool 值。
使用谓词测试 text()
值并计算满足条件的数量:
count(./group/elem1/text()[.='test1'])
关于xml - XSD 中的 X-Path 2.0(断言): "count(//elem/text() = ' test') > 0"always true,,即使字符串不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37141775/
有没有办法像这样输出一个数组: (elem,elem,elem) 例如,如果数组是[2, 3, 4],它会打印: (2,3,4) 最佳答案 puts "(#{array.join ','})" 这是一
我正在使用 g++ -g 编译我的代码,但我在标题中收到了错误消息。 这个错误与我做的一个函数有关,它的签名是: void addHead( Elem *&start , Elem *newStart
我使用的代码如 $('.elem',elem)、$('.elem',elem).tabs()。 $(".elem") 用于选择具有该类的元素。 但是逗号后面的是什么?它有什么用? 最佳答案 $('.e
你可能看过我之前关于 jQuery 升级的主题。所以最后我们将jQUery从1.4.2升级到1.6.1,但我们遇到了以下问题: elem is undefinedif ( elem.nodeName
typedef struct Element { struct Element *next; void *data; } Element; 在 pop 函数中,(!(elem = *s
我今天想知道 javascript 函数。我知道 jQuery 是一个 javascript 库,可以在带有点的元素上调用函数。 javascript 有时会做同样的事情(例如:.toFixed())
这个问题在这里已经有了答案: val() vs. text() for textarea (2 个答案) 关闭 5 年前。 这很奇怪。显然,我可以同时使用 .val() 和 .text() 来操作文
这个问题已经有答案了: Which way to test if an element is checked is better? .is(':checked') or .prop('checked'
所以,基本上我想检测用户何时将鼠标悬停在一个元素上(不同的 div 元素,不是父元素或同级元素),并且当发生悬停时,添加 :hover到我的另一个 div 元素。我的其他 div 元素状态的 :hov
Type Driven Development with Idris 一书介绍了这个练习: Define a possible method that fits the signature: two
在下面的代码中,两个选项似乎都分配了相同的资源 func Allocate(v interface{}) error { rv := reflect.ValueOf(v) if rv.
我有以下内容: elem :: Eq a => a -> [a] -> Bool elem _ [] = False elem x (y:ys) = x == y || elem x ys 我如何证明
每当我在本地系统中运行脚本时,游标都能正常工作,当我在docker中运行时,我获取了一个错误,所以任何人都会告诉我哪里出了问题,或者这个问题是不是包端的问题。。当我在当地跑的时候,我无头:假,当时无头
我有外部 RSS 提要填充以下重复出现的类 elements 。 {teaserImage} {teaserImage} {teaserImage} 我想简单地获取 :first 实例,该实例也是来自
使用 python 的 openpyxl 加载 xlsm 文件,然后在将一些数据添加到特定工作表中的特定 7 个单元格后保存/关闭它时,我收到警告。问题是我收到了一个“FutureWarning”,我
问题是将列表元素的连续副本打包到子列表中。 我不明白elem在这里使用单个元素, 例如, pack [1,1,2,2,3,4] 然后x将为 1 和 (head (pack xs))将是 1。 怎么能:
$(elem) 的用途是什么?我什么时候使用它? 我的 javascript 函数有问题,我有 3 个表单,这 3 个表单有时共享相同的字段类,因此当我尝试对其中一个表单进行验证时,即使它已正确填写,
我有一个相当简单的问题,我通常可以自己调试,但我现在似乎遇到了很多问题。 我正在创建一个链表数据结构,我做了两个函数,一个返回前面的 Elem,一个返回最后一个 Elem。问题是编译器说 Elem 没
我开始使用 ES6 粗箭头函数符号,我非常喜欢它。但是我对它的上下文有点困惑。据我所知,关键字 this inside fat arrow function 指的是函数当前运行的上下文。我想做一些简单
Go语言程序中对指针获取反射对象时,可以通过 reflect.Elem() 方法获取这个指针指向的元素类型。这个获取过程被称为取元素,等效于对指针类型变量做了一个 *操作,代码如下: packag
我是一名优秀的程序员,十分优秀!