Reputation: 1293
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!!
Upvotes: 0
Views: 343
Reputation: 21638
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).
<xs:element name="Conceptos">
<xs:complexType>
<xs:sequence>
<xs:element name="Concepto" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:choice minOccurs="0">
<xs:element name="InformacionAduanera" type="cfdi:t_InformacionAduanera" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="CuentaPredial" minOccurs="0">...</xs:element>
</xs:choice>
<xs:element name="OptDetail" type="cfdi:optDetail" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="cantidad" use="required">
...
</xs:attribute>
...
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="optDetail">
...
</xs:complexType>
Upvotes: 1