Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
检查xml模式中与另一个模式的依赖关系中的标记_Xml_Validation_Xsd_Schema_Xml Validation - Fatal编程技术网

检查xml模式中与另一个模式的依赖关系中的标记

检查xml模式中与另一个模式的依赖关系中的标记,xml,validation,xsd,schema,xml-validation,Xml,Validation,Xsd,Schema,Xml Validation,我有以下示例xml: <ip_addresses> <ip_address> <type>local</type> <ip>192.168.1.1</ip> </ip_address> <ip_address> <type>public</type> <ip>82.125.1.1</ip>

我有以下示例xml:

<ip_addresses>
   <ip_address>
      <type>local</type>
      <ip>192.168.1.1</ip>
   </ip_address>

   <ip_address>
      <type>public</type>
      <ip>82.125.1.1</ip>
   </ip_address>
</ip_addresses>

地方的
192.168.1.1
公众的
82.125.1.1
如何在xml模式中使用不同的正则表达式对
标记中的值进行ip检查

我还尝试了类似于
192.168.1.1
的方法,但无法使xml模式正常工作

谢谢你的帮助
Marten

在XSD 1.0中,不能使一个元素的类型以另一个元素的值为条件

在XSD1.1中,可以使用断言来实现这一点。例如(在ip_地址级别),您可以编写

<xs:assert test="(@type='local' and @ip='192.168.1.1') or @type='public'"/>


为什么是regex而不是xpath?我指的是用于ip验证的regex。我无法通过xpath或?类似这样的值=“(192)\.(168)\.(112)\.(25[0-5]| 2[0-4][0-9]|[01]?[0-9][0-9]?)好的,现在我明白你的意思了。可能的重复。另外,检查一下。但是@ip='XYZ'不能像我在上面的评论中那样是正则表达式,或者?我理解你的答案,我只能针对每个xs:assert断言一个ip,或者?不,你可以使用任何XPath表达式,例如,你可以使用matches()使用正则表达式。我不知道你为什么建议使用正则表达式,OP要求中似乎没有任何东西需要它,尽管问题的陈述非常模糊。