I'm having some trouble with a very simple schema. In the xml body that the schema specifies the first child of the root element is specified as having xmlns="" which is causing validation problems for me.
I've searched and searched and tried repeatedly to figure out why it's happening and I've not had any success. This is causing a larger problem with my server code as I'm composing an xml body and validation of it is failing due to my element not having xmlns="".
I would like to understand why the xmlns="" is resulting from the schema definition and how to fix this.
Here is the schema:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org"
xmlns="http://www.example.org">
<xs:simpleType name="XYZ">
<xs:restriction base="xs:string">
<xs:maxLength value="10"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="ABC">
<xs:sequence>
<xs:element name="PQR" type="XYZ"/>
</xs:sequence>
</xs:complexType>
<xs:element name="A1">
<xs:complexType>
<xs:sequence>
<xs:element name="result" type="ABC"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Based off of this schema, the following document is created:
<?xml version="1.0" encoding="UTF-8"?>
<A1 xmlns="http://www.example.org">
<result xmlns="">
<PQR></PQR>
</result>
</A1>
I would like this:
<?xml version="1.0" encoding="UTF-8"?>
<A1 xmlns="http://www.example.org">
<result>
<PQR></PQR>
</result>
</A1>
I've been looking at this and trying things for about a day now. Shouldn't the <result>
element just be part of the targetnamespace making xmlns="" unnecessary?
Additionally when I try to validate it I'm getting the following error:
System ID: /Users/dev/Desktop/Untitled3.xml
Main validation file: /Users/dev/Desktop/Untitled3.xml
Schema: /Users/dev/Desktop/test.xsd
Engine name: Xerces
Severity: error
Description: cvc-complex-type.2.4.a: Invalid content was found starting with element '{"http://www.example.org":PQR}'. One of '{PQR}' is expected.
Start location: 4:10
End location: 4:13
URL: http://www.w3.org/TR/xmlschema-1/#cvc-complex-type