I am new to XML and now working on parsing XML file. While validating XML file, we are receiving an error:
Invalid content was found starting with element 'nxce:element'. No child element is expected at this point.
The XSD used choice indicator with 4 elements. XML file has entries for all 4 elements hence we believe that the error is occurred because of wrong use of choice indicator. The actual XML is very complex, so to check working of choice indicator and to reproduce same error with simpler file, I developed a XML file and an XSD file. I was expecting error when I validated XML file, but XML file was validated without any error.
XML File
<?xml version="1.0" encoding="UTF-8"?>
<employee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="file:///EmployeeSchema.xsd">
<emp>
<empid>3</empid>
<name>Name</name>
<address>
<building>Building</building>
<pincode>Pincode</pincode>
<street>Street</street>
<area>Area</area>
</address>
</emp>
</employee>
XSD File
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="employee">
<xs:complexType>
<xs:sequence>
<xs:element name="emp">
<xs:complexType>
<xs:sequence>
<xs:element name="empid" type="xs:string"/>
<xs:element name="name" type="xs:string"/>
<xs:element name="address">
<xs:complexType>
<xs:choice>
<xs:sequence>
<xs:element name="street" type="xs:string" />
<xs:element name="area" type="xs:string" />
</xs:sequence>
<xs:sequence>
<xs:element name="building" type="xs:string" />
<xs:element name="pincode" type="xs:string" />
</xs:sequence>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
As the choice
indicator specifies that either one child element or another can occur, I was expecting to get error as in address
tag, I used all 4 elements. But XML was validated without any error in eclipse.
Could you please let me know, why I am not receiving error while validating XML?