I have this XML file and I must validate it with a XSD file. I am creating the XSD file but I can't do it.
A example of my XML file
<datos>
<elemento tipoelemento="CABECERA">
<atributo>
<nombre>VERSION</nombre>
<valor>1.0</valor>
</atributo>
<atributo>
<nombre>BRIGADA</nombre>
<valor>JADSJL</valor>
</atributo>
<atributo>
<nombre>BUZON</nombre>
<valor>ASDKLFJKA</valor>
</atributo>
</elemento>
<elemento tipoelemento="INT">
<atributo>
<nombre>EQUNR</nombre>
<valor>9879979797764644</valor>
</atributo>
<atributo>
<nombre>ZDPYC</nombre>
<valor>N</valor>
</atributo>
<atributo>
<nombre>ZDPATORD</nombre>
<valor />
</atributo>
</elemento>
<elemento tipoelemento="EXT">
<atributo>
<nombre>zaufnr</nombre>
<valor>54737674674</valor>
</atributo>
<atributo>
<nombre>zhoras</nombre>
<valor>6</valor>
</atributo>
<atributo>
<nombre>zpuesto</nombre>
<valor>sdgfsg</valor>
</atributo>
</elemento>
My XSD file
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning"
elementFormDefault="qualified"
vc:minVersion="1.1">
<xs:element name="datos">
<xs:complexType>
<xs:sequence>
<xs:element name="elemento" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="elemento" minOccurs="1" maxOccurs="1" type="CABECERA" />
<xs:element name="elemento" minOccurs="0" maxOccurs="unbounded" type="INT" />
<xs:element name="elemento" minOccurs="0" maxOccurs="unbounded" type="EXT" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="CABECERA">
<xs:sequence>
<xs:element name="atributo" minOccurs="1" maxOccurs="1" type="VERSION" />
<xs:element name="atributo" minOccurs="1" maxOccurs="1" type="BRIGADA" />
<xs:element name="atributo" minOccurs="1" maxOccurs="1" type="BUZON" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="VERSION">
<xs:sequence>
<xs:element name="nombre" type="xs:string" minOccurs="1" fixed="VERSION" />
<xs:element name="valor" type="xs:string" minOccurs="1" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="BRIGADA">
<xs:sequence>
<xs:element name="nombre" type="xs:string" minOccurs="1" fixed="BRIGADA" />
<xs:element name="valor" type="xs:string" minOccurs="1" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="BUZON">
<xs:sequence>
<xs:element name="nombre" type="xs:string" minOccurs="1" fixed="BUZON" />
<xs:element name="valor" type="xs:string" minOccurs="1" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="INT">
<xs:sequence>
<xs:element name="atributo" minOccurs="1" maxOccurs="1" type="EQUNR" />
<xs:element name="atributo" minOccurs="1" maxOccurs="1" type="ZDPYC" />
<xs:element name="atributo" minOccurs="1" maxOccurs="1" type="ZDPATORD" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="EQUNR">
<xs:sequence>
<xs:element name="nombre" type="xs:string" minOccurs="1" fixed="EQUNR" />
<xs:element name="valor" type="xs:string" minOccurs="1" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="ZDPYC">
<xs:sequence>
<xs:element name="nombre" type="xs:string" minOccurs="1" fixed="ZDPYC" />
<xs:element name="valor" type="xs:string" minOccurs="1" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="ZDPATORD">
<xs:sequence>
<xs:element name="nombre" type="xs:string" minOccurs="1" fixed="ZDPATORD" />
<xs:element name="valor" type="xs:string" minOccurs="1" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="EXT">
<xs:sequence>
<xs:element name="atributo" minOccurs="1" maxOccurs="1" type="zaufnr" />
<xs:element name="atributo" minOccurs="1" maxOccurs="1" type="zhoras" />
<xs:element name="atributo" minOccurs="1" maxOccurs="1" type="zpuesto" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="zaufnr">
<xs:sequence>
<xs:element name="nombre" type="xs:string" minOccurs="1" fixed="zaufnr" />
<xs:element name="valor" type="xs:string" minOccurs="1" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="zhoras">
<xs:sequence>
<xs:element name="nombre" type="xs:string" minOccurs="1" fixed="zhoras" />
<xs:element name="valor" type="xs:string" minOccurs="1" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="zpuesto">
<xs:sequence>
<xs:element name="nombre" type="xs:string" minOccurs="1" fixed="zpuesto" />
<xs:element name="valor" type="xs:string" minOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:schema>
How can I validate the following points in this XSD?
- Always, the element with
elementtype="CABECERA"
have those sameattribute.name
and this element is required - Always, the element with
elementtype="INT"
have those sameattribute.name
, but this element is optional. - Always, the element with
elementtype="EXT"
have those sameattribute.name
, but this element is optional.
To create this xsd I have followed this link: click here
but this xsd throws an exception:
cos-element -istent: Error para el tipo 'CABECERA'. Aparecen en el grupo de modelos varios elementos con el nombre 'atributo' y con tipos diferentes.
I can´t abandon this design, I should validate this xml.
could somebody help me?