xml - 使用 XSD 1.1 进行 xml 验证
问题描述
我没有使用 XSD 文件验证的经验,我必须使用 XSD 1.1 验证 xml 文件,但出现下一个错误:
lineNumber: 10; columnNumber: 71; c-cta-xpath: The XPath expression '@tipoelemento = CABECERA' couldn't compile successfully in 'cta-subset' mode, during CTA evaluation.
文件.xml
<datos>
<elemento tipoelemento="CABECERA">
<atributo>
<nombre>VERSION</nombre>
<valor>1.0</valor>
</atributo>
<atributo>
<nombre>BRIGADA</nombre>
<valor>JADSJL</valor>
</atributo>
<atributo>
<nombre>BUZON</nombre>
<valor>ASDKLFJKA</valor>
</atributo>
</elemento>
文件.xsd
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning"
elementFormDefault="qualified"
vc:minVersion="1.1">
<xs:element name="datos">
<xs:complexType>
<xs:sequence>
<xs:element name="elemento" minOccurs="1" maxOccurs="1">
<xs:alternative test="@tipoelemento = 'CABECERA'" type="cabecera"/>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="cabecera">
<xs:sequence>
<xs:element name="atributo" minOccurs="1" maxOccurs="1" type="VERSION" />
<xs:element name="atributo" minOccurs="1" maxOccurs="1" type="BRIGADA" />
<xs:element name="atributo" minOccurs="1" maxOccurs="1" type="BUZON" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="VERSION">
<xs:sequence>
<xs:element name="nombre" type="xs:string" minOccurs="1" fixed="VERSION" />
<xs:element name="valor" type="xs:string" minOccurs="1" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="BRIGADA">
<xs:sequence>
<xs:element name="nombre" type="xs:string" minOccurs="1" fixed="BRIGADA" />
<xs:element name="valor" type="xs:string" minOccurs="1" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="BUZON">
<xs:sequence>
<xs:element name="nombre" type="xs:string" minOccurs="1" fixed="BUZON" />
<xs:element name="valor" type="xs:string" minOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:schema>
我没有这方面的经验,对不起!
我跟着这个链接点击这里
我在此链接中看到单击此处,我需要使用完整的 XPath 2.0,但我不知道该怎么做。
我该如何解决这个问题?
问候
解决方案
条件类型赋值中使用的 XPath 表达式仅限于访问属性,它们不能访问子元素。
您的错误是在您的表达式中,@tipoelemento = CABECERA
,CABACERA
被解释为child::CABECERA
,即对子元素的引用。我想你在这里想要一个字符串文字,这将是@tipoelemento = 'CABECERA'
字符串在引号中的位置。
推荐阅读
- git - 如何共享排除目录?
- node.js - 在 mongoDB 中流式传输时 insertMany 无法正常工作
- c++11 - (解决用户错误)c++11 make_shared
(新类)内存泄漏 - flutter - 如果一个小部件声明为 const,它是否会传播给它的孩子?
- javascript - 如何在 ui-grid 角度选择中获取字符串的值并将其传递给 Spring 控制器
- python - 在python的元组中没有重复的随机选择
- html - 如何在使用 Bootstrap 4 加载页面后禁用加载器/微调器?
- javascript - Node.JS:具有多个不同 Socks5 问题的 Puppeteer 多线程实例
- scala - 在scala中覆盖父方法
- machine-learning - 值错误 - 检查目标时出错 - LSTM