I am trying to create an XSD to validate a series of documents generated in XML format .
I have tried the following:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="proceso_cajero">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="evento">
<xs:complexType>
<xs:sequence>
<xs:element name="ID_INSTANCIA" type="xs:string" />
<xs:element name="ACTIVIDAD" type="xs:string" />
</xs:sequence>
<xs:any minOccurs="1"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
What I need and am trying to do in that piece of code is to validate that the XML file has 2 elements inside the element "evento"
in that order "ID_INSTANCIA"
- "ACTIVIDAD"
and then several elements but not required. If it is mandatory for at least one element to come after the sequence .
The target XML file can have this structure:
<?xml version="1.0" encoding="UTF-8" ?>
<proceso_cajero>
<evento>
<ID_INSTANCIA>XXXXX</ID_INSTANCIA>
<ACTIVIDAD>XXXXXXXXX</ACTIVIDAD>
<MONEDA>XXX</MONEDA>
<MONTO>XXX</MONTO>
</evento>
</proceso_cajero>
When trying to perform the validation, it shows me an error on the line where I declare the element <xs:any>
:
"Unable to parse schema file, the content is not valid expected is (annotation,simplecontent,complexcontent, ... )"
The mandatory elements must have the attribute
minOccurs="1"
and after closing onexs:sequence
you cannot put more elements, you must start anotherxs:sequence
or another structure.In your case, the element
any
is part of the sequence as the last element and the scheme would look like this: