c# - 通配符 ##any 错误 xml 架构验证
问题描述
根据 C# 中的架构验证 XSD 时出现上述错误。Schema 查找列出的标签,其他标签是可选的。下面是我的 XSD 文件。xml 文件需要如何修改,以确保它具有以下 XSD 中列出的标签并忽略额外的标签。它正在使用 XML 文本阅读器进行架构验证
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="InvoiceExport" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="InvoiceExport" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Invoice">
<xs:complexType>
<xs:sequence>
<xs:element name="Invoice_ID" type="xs:string" minOccurs="1" />
<xs:element name="BillingEntity" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Name" type="xs:string" minOccurs="1" />
<xs:element name="VendorNumber" type="xs:string" minOccurs="1" />
<xs:any processContents="lax" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="InvoiceBaseInfo" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="InvoiceDate" type="xs:string" minOccurs="1" />
<xs:element name="BillingEntityInvoiceNumber" type="xs:string" minOccurs="1" />
<xs:element name="ReceivedDate" type="xs:string" minOccurs="1" />
<xs:element name="AdjustedBilledAmount" type="xs:string" minOccurs="1" />
<xs:element name="UserFields" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:all>
<xs:element name="FirstApproverID" type="xs:string" minOccurs="1" />
<xs:element name="LastApproverID" type="xs:string" minOccurs="1" />
<xs:element name="LegalSpendCode" type="xs:string" minOccurs="0" />
</xs:all>
</xs:complexType>
</xs:element>
<xs:any processContents="lax" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="InvoiceMatter" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Priority_CD" type="xs:string" minOccurs="1" />
<xs:element name="InvoiceMatterDetail" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:any processContents="lax" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="InvoiceMatterAllocation" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="AllocationAmount" type="xs:string" minOccurs="1" />
<xs:element name="ChargeBackAccount1" type="xs:string" minOccurs="1" />
<xs:element name="ChargeBackAccount2" type="xs:string" minOccurs="1" />
<xs:element name="ChargeBackAccount3" type="xs:string" minOccurs="1" />
<xs:element name="UserFields" type="xs:string" minOccurs="0" />
<xs:any processContents="lax" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="InvoiceMatterApproval" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="EmployeeName" type="xs:string" minOccurs="1" />
<xs:any processContents="lax" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:any processContents="lax" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
解决方案
问题是您的架构允许任意数量的称为 InvoiceMatter 的元素,后跟一个可以具有任何名称的元素(包括名称 InvoiceMatter);因此,如果找到 InvoiceMatter 元素,则它是否匹配特定元素粒子或通配符是不明确的。
XSD 1.1 通过说特定元素粒子总是优先解决这个问题,因此一种解决方案是简单地使用 XSD 1.1 处理器(例如 Saxon)。
如果您不能这样做,通常的 XSD 1.0 解决方案是使用 xs:any 通配符上的 targetNamespace 属性来通过命名空间(例如targetNamespace="##other"
)来限制它。但这是对您的设计的改变;如果您想允许同一名称空间中的元素,那么您遇到了问题。
推荐阅读
- php - Imagick getImagePixelColour alpha不一致
- javascript - 如果缺少值,如何抛出异常?
- python - Nginx 阻止来自 HTML 表单的数据
- reporting-services - 根据表达式隐藏报告标题 (SSRS) 会出错
- php - Linux 通过 Apache Webserver 从 PHP 执行 C 可执行文件
- jquery - 在递归函数组件中将 JQuery (toggleClass, slideToggle) 代码转换为 Reactjs 等效项
- tritonserver - 是否可以在 Nvidia Triton 推理服务器模型存储库中使用另一个模型和自定义 Python 模型?
- nestjs - 在nestjs库中获取会话和请求数据
- php - laravel - 无法声明类 Carbon\Carbon,因为该名称已在使用中
- jmeter - 通过 jmeter 记录 FlexCube 应用程序时获取加密请求和响应