Reputation:
I'm trying to understand what is the issue with this xml file:
<?xml version="1.0" encoding="UTF-8"?>
<Request
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://website.com/types Types.xsd"
xmlns="http://website.com/types"
version="1.0">
<Type>ONE</Type>
<FileName>request.xml</FileName>
<File>base64_encoded_file_which_seems_to_be_ok</File>
</Request>
the xsd is:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
xmlns="http://website.com/types"
targetNamespace="http://website.com/types"
version="1.0">
<xs:import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd"/>
<xs:element name="Request" type="FileType"/>
<xs:complexType name="FileType">
<xs:sequence>
<xs:element name="Type" type="StringType" />
<xs:element name="FileName" type="FileNameType" />
<xs:element name="File" type="xs:base64Binary" xmime:expectedContentTypes="*/*" xmlns:xmime="http://www.w3.org/2005/05/xmlmime" />
<xs:element ref="ds:Signature" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="version" type="VersionType" use="required"/>
</xs:complexType>
<xs:simpleType name="FileNameType">
<xs:restriction base="xs:normalizedString">
<xs:pattern value="[a-zA-Z0-9_\.]{9,50}" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="StringType">
<xs:restriction base="xs:normalizedString">
<xs:pattern value="[A-Za-z_]{1,100}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="VersionType">
<xs:restriction base="xs:string">
<xs:maxLength value="5"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
I'm getting this error:
Invalid content was found starting with element 'Type'. One of '{Type}' is expected. Row: 7 - Column: 20.
Is my xml good, right?
I composed it reading the italian government documentation.
Upvotes: 1
Views: 74
Reputation: 242123
You need to tell the schema the TipoRichiesta element belongs to the same namespace as the whole document. Add the following attribute to the xs:schema
:
elementFormDefault="qualified"
See What does elementFormDefault do in XSD? for a detailed explanation.
Or, if you can't change the schema, you need to use the namespace only for the root element, not the other elements:
<?xml version="1.0" encoding="UTF-8"?>
<rsm:FileRichiesta
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ivaservizi.agenziaentrate.gov.it/docs/xsd/ServiziMassivi/input/RichiestaServiziMassivi/v1.0 RichiestaServiziMassivi_v1.0.xsd"
xmlns:rsm="http://ivaservizi.agenziaentrate.gov.it/docs/xsd/ServiziMassivi/input/RichiestaServiziMassivi/v1.0"
versione="1.0">
<TipoRichiesta>FATT</TipoRichiesta>
<NomeFile>request.xml</NomeFile>
<File>YmFzZTY0X2VuY29kZWRfZmlsZV93aGljaF9zZWVtc190b19iZV9vawo=</File>
</rsm:FileRichiesta>
Upvotes: 1