Xsd 我可以在带有扩展的模式中使用唯一约束吗?
例子Xsd 我可以在带有扩展的模式中使用唯一约束吗?,xsd,schema,Xsd,Schema,例子 <?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns="http://www.irs.gov/efile" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.irs.gov/efile" elementFormDefault="qualified" attributeFormDefault="unqualified
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns="http://www.irs.gov/efile" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.irs.gov/efile"
elementFormDefault="qualified"
attributeFormDefault="unqualified"
version="1.0">
<xsd:element name="Form1120" type="Form1120Type">
<xsd:unique name="uniqueCreditCode">
<xsd:selector xpath="IncomeTaxCredits"/>
<xsd:field xpath="CreditCode"/>
</xsd:unique>
</xsd:element>
<xsd:complexType name="Form1120Type">
<xsd:sequence>
<xsd:element name="CreditAvailable" type="CheckboxType" minOccurs="0"/>
<xsd:element name="IncomeTaxCredits" maxOccurs="10">
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="MSOtherIncFrancCreditsType">
<xsd:attribute name="referenceDocumentId" type="IdListType"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
10
100
10
100
假设MSOtherIncFrancCreditsType包含两个元素-CreditCode和Amount。CreditCode 10在整个xml文档中只能使用一次。在本例中,它被使用了两次。为什么基于模式这是有效的?我认为应该使用带有前缀的名称空间。更改:
<IncomeTaxCredits>
<CreditCode>10</CreditCode>
<Amount>100</Amount>
<IncomeTaxCredits>
<IncomeTaxCredits>
<CreditCode>10</CreditCode>
<Amount>100</Amount>
<IncomeTaxCredits>
致:
然后在xpath中使用此前缀,如下所示:
<xsd:schema xmlns:p="http://www.irs.gov/efile" ...>
<xsd:element name="Form1120" type="Form1120Type">
<xsd:unique name="uniqueCreditCode">
<xsd:selector xpath="p:IncomeTaxCredits"/>
<xsd:field xpath="p:CreditCode"/>
</xsd:unique>
</xsd:element>
完整的xsd应该如下所示:
<xsd:schema xmlns:p="http://www.irs.gov/efile" ...>
<xsd:element name="Form1120" type="Form1120Type">
<xsd:unique name="uniqueCreditCode">
<xsd:selector xpath="p:IncomeTaxCredits"/>
<xsd:field xpath="p:CreditCode"/>
</xsd:unique>
</xsd:element>
我认为应该使用带有前缀的名称空间。更改:
<IncomeTaxCredits>
<CreditCode>10</CreditCode>
<Amount>100</Amount>
<IncomeTaxCredits>
<IncomeTaxCredits>
<CreditCode>10</CreditCode>
<Amount>100</Amount>
<IncomeTaxCredits>
致:
然后在xpath中使用此前缀,如下所示:
<xsd:schema xmlns:p="http://www.irs.gov/efile" ...>
<xsd:element name="Form1120" type="Form1120Type">
<xsd:unique name="uniqueCreditCode">
<xsd:selector xpath="p:IncomeTaxCredits"/>
<xsd:field xpath="p:CreditCode"/>
</xsd:unique>
</xsd:element>
完整的xsd应该如下所示:
<xsd:schema xmlns:p="http://www.irs.gov/efile" ...>
<xsd:element name="Form1120" type="Form1120Type">
<xsd:unique name="uniqueCreditCode">
<xsd:selector xpath="p:IncomeTaxCredits"/>
<xsd:field xpath="p:CreditCode"/>
</xsd:unique>
</xsd:element>
您的XML似乎无效。您能验证它是否被复制、粘贴和格式正确吗?我重新发布了代码。@丽塔:检查我是否正确解释了编辑内容。是的(关于示例),您的XML似乎无效。您能确认它是否被复制、粘贴并正确格式化吗?我重新发布了代码。@丽塔:检查我是否正确解释了我的编辑。是的(关于示例),您知道其他解决方案吗?我想您别无选择。必须使用命名空间前缀。如果不使用XPath,则可以使用默认名称空间或名称空间前缀。是否知道其他解决方案?我认为您没有其他选择。必须使用命名空间前缀。如果不使用XPath,则可以使用默认名称空间或名称空间前缀。