我应该在 XSD 架构中的哪里添加复杂类型元素
我正在开发 XSD 架构,我被要求在概念节点上添加一个新的复杂类型,它看起来像这样:
<xs:element name="Conceptos">
<xs:complexType>
<xs:sequence>
<xs:element name="Concepto" maxOccurs="unbounded">
<xs:complexType>
<xs:choice minOccurs="0">
<xs:element name="InformacionAduanera" type="cfdi:t_InformacionAduanera" minOccurs="0" maxOccurs="unbounded">
</xs:element>
<xs:element name="CuentaPredial" minOccurs="0">
<xs:annotation>
<xs:documentation>Nodo opcional para asentar el número de cuenta predial con el que fue registrado el inmueble, en el sistema catastral de la entidad federativa de que trate.</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:attribute name="numero" use="required">
<xs:annotation>
<xs:documentation>Atributo requerido para precisar el número de la cuenta predial del inmueble cubierto por el presente concepto en caso de recibos de arrendamiento.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:whiteSpace value="collapse"/>
<xs:minLength value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:choice>
<xs:attribute name="cantidad" use="required">
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:whiteSpace value="collapse"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="unidad" use="optional">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:whiteSpace value="collapse"/>
<xs:minLength value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="noIdentificacion" use="optional">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:whiteSpace value="collapse"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="descripcion" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:whiteSpace value="collapse"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="valorUnitario" type="cfdi:t_Importe" use="required">
</xs:attribute>
<xs:attribute name="importe" type="cfdi:t_Importe" use="required">
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
XSD 的这一部分验证 XML 的以下片段
<cfdi:Conceptos>
<cfdi:Concepto cantidad="1.0" noIdentificacion="15" descripcion="Autotransporte terrestre de bienes" valorUnitario="10" importe="10" />
<cfdi:Concepto cantidad="1.0" noIdentificacion="19" descripcion="PF a PM Retencion 2/3 IVA" valorUnitario="10" importe="10">
<cfdi:InformacionAduanera numero="123456" fecha="2011-07-13" aduana="Nuevo Laredo"/>
</cfdi:Concepto>
所以我想做的是添加一个新元素,因此 xml 如下所示:
<cfdi:Conceptos>
<cfdi:Concepto cantidad="1.0" noIdentificacion="15" descripcion="Autotransporte terrestre de bienes" valorUnitario="10" importe="10" />
<cfdi:Concepto cantidad="1.0" noIdentificacion="19" descripcion="PF a PM Retencion 2/3 IVA" valorUnitario="10" importe="10">
<cfdi:InformacionAduanera numero="123456" fecha="2011-07-13" aduana="Nuevo Laredo"/>
<cfdi:OptDetail name="TransID" value="34545" />
<cfdi:OptDetail name="Purchase" value="8745" />
<cfdi:OptDetail name="StoreID" value="1" />
<cfdi:OptDetail name="someName" value="SomeValue" />
<cfdi:OptDetail name="XXXX" value="YYYY" />
.
.
.
N
</cfdi:Concepto>
如您所见,我想为每个 Concepto 添加一个新元素 (optDetail) ,其中 minOccurs = 0 且 maxOccurs= unbouded。与 InformacionAduanera 节点几乎相同(我不认为在这里显示此类型的定义有什么意义),但是,InformacionAduanera 受到 Choice 限制。
所以我所做的是,我首先定义了我的类型
<xs:complexType name="optDetail">
<xs:attribute name="name" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:whiteSpace value="collapse"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="value" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:whiteSpace value="collapse"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
,我尝试添加到 XSD 但没有成功,我收到了诸如元素节点放错位置或元素标签出现次数过多之类的错误,所以问题是我应该把它放在哪里它来验证我上面显示的xml???
谢谢!!
I'm working on a XSD Schema, I've been asked to add a new complex type on the concepts node, it looks like this:
<xs:element name="Conceptos">
<xs:complexType>
<xs:sequence>
<xs:element name="Concepto" maxOccurs="unbounded">
<xs:complexType>
<xs:choice minOccurs="0">
<xs:element name="InformacionAduanera" type="cfdi:t_InformacionAduanera" minOccurs="0" maxOccurs="unbounded">
</xs:element>
<xs:element name="CuentaPredial" minOccurs="0">
<xs:annotation>
<xs:documentation>Nodo opcional para asentar el número de cuenta predial con el que fue registrado el inmueble, en el sistema catastral de la entidad federativa de que trate.</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:attribute name="numero" use="required">
<xs:annotation>
<xs:documentation>Atributo requerido para precisar el número de la cuenta predial del inmueble cubierto por el presente concepto en caso de recibos de arrendamiento.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:whiteSpace value="collapse"/>
<xs:minLength value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:choice>
<xs:attribute name="cantidad" use="required">
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:whiteSpace value="collapse"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="unidad" use="optional">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:whiteSpace value="collapse"/>
<xs:minLength value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="noIdentificacion" use="optional">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:whiteSpace value="collapse"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="descripcion" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:whiteSpace value="collapse"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="valorUnitario" type="cfdi:t_Importe" use="required">
</xs:attribute>
<xs:attribute name="importe" type="cfdi:t_Importe" use="required">
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
This part of the XSD validates the following fragment of an XML
<cfdi:Conceptos>
<cfdi:Concepto cantidad="1.0" noIdentificacion="15" descripcion="Autotransporte terrestre de bienes" valorUnitario="10" importe="10" />
<cfdi:Concepto cantidad="1.0" noIdentificacion="19" descripcion="PF a PM Retencion 2/3 IVA" valorUnitario="10" importe="10">
<cfdi:InformacionAduanera numero="123456" fecha="2011-07-13" aduana="Nuevo Laredo"/>
</cfdi:Concepto>
So what I want to do is to add a new element, so the xml look like this:
<cfdi:Conceptos>
<cfdi:Concepto cantidad="1.0" noIdentificacion="15" descripcion="Autotransporte terrestre de bienes" valorUnitario="10" importe="10" />
<cfdi:Concepto cantidad="1.0" noIdentificacion="19" descripcion="PF a PM Retencion 2/3 IVA" valorUnitario="10" importe="10">
<cfdi:InformacionAduanera numero="123456" fecha="2011-07-13" aduana="Nuevo Laredo"/>
<cfdi:OptDetail name="TransID" value="34545" />
<cfdi:OptDetail name="Purchase" value="8745" />
<cfdi:OptDetail name="StoreID" value="1" />
<cfdi:OptDetail name="someName" value="SomeValue" />
<cfdi:OptDetail name="XXXX" value="YYYY" />
.
.
.
N
</cfdi:Concepto>
As you can see, I want to add a new element (optDetail) for each Concepto with minOccurs = 0 and maxOccurs= unbouded.It's almost the same thing as the InformacionAduanera node (I don't see the point of showing here the definition of this type) but, InformacionAduanera is under a Choice restriction, .
So what I did, is I defined my type first
<xs:complexType name="optDetail">
<xs:attribute name="name" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:whiteSpace value="collapse"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="value" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:whiteSpace value="collapse"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
I tried to add in to the XSD but without success, I got errors like the element node is misplaced or or too many occurrences for the element tag, so the question is where should I put it to validate my the xml shown above???
Thanks!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保您的 optDetail 复杂类型添加到 xs:schema 元素下(必须是全局的,因为它已命名)。答案如下所示(为了简洁起见,我删除了内容)。
Make sure that your optDetail complex type is added under the xs:schema element (must be global, since it is named). The answer is shown below (I've removed content for brevity).