[英]Wildcard ##any error xml schema validation
針對C#中的架構驗證XSD時遇到上述錯誤。 模式將查找列出的標簽,而其他標簽是可選的。 以下是我的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"
)。 但這就是您設計的改變; 如果您想允許元素在相同的名稱空間中,那么就會有問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.