java - Invalid Content Was Found Starting With Element -
i have error writing xml , xsd. wrote students.xsd:
<?xml version="1.0" encoding="utf-8" ?> <xs:schema attributeformdefault="unqualified" xmlns:xs="http://www.w3.org/2001/xmlschema" elementformdefault="qualified"> <xs:element name="students"> <xs:complextype> <xs:sequence> <xs:element name="student"> <xs:complextype> <xs:sequence> <xs:element name="name"> <xs:complextype> <xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> </xs:sequence> </xs:complextype> </xs:element> <xs:element name="faculty"> <xs:simpletype> <xs:restriction base="xs:string"> <xs:enumeration value="fkp"/> <xs:enumeration value="fitu"/> <xs:enumeration value="fre"/> <xs:enumeration value="fksis"/> <xs:enumeration value="ftk"/> <xs:enumeration value="fnido"/> </xs:restriction> </xs:simpletype> </xs:element> <xs:element name="address"> <xs:complextype> <xs:sequence> <xs:element name="country"> <xs:simpletype> <xs:restriction base="xs:string"> <xs:minlength value="2"/> <xs:maxlength value="20"/> </xs:restriction> </xs:simpletype> </xs:element> <xs:element name="city"> <xs:simpletype> <xs:restriction base="xs:string"> <xs:minlength value="2"/> <xs:maxlength value="20"/> </xs:restriction> </xs:simpletype> </xs:element> <xs:element name="street"> <xs:simpletype> <xs:restriction base="xs:string"> <xs:minlength value="2"/> <xs:maxlength value="30"/> </xs:restriction> </xs:simpletype> </xs:element> </xs:sequence> </xs:complextype> </xs:element> <xs:element name="phone"> <xs:simpletype> <xs:restriction base="xs:positiveinteger"> <xs:length value="6"/> <xs:pattern value="[0-9]"/> </xs:restriction> </xs:simpletype> </xs:element> </xs:sequence> <xs:attribute name="id" type="xs:int" use="required"/> </xs:complextype> </xs:element> </xs:sequence> </xs:complextype> </xs:element> </xs:schema>
and have file students.xml:
<?xml version="1.0" encoding="utf-8" ?> <students xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:nonamespaceschemalocation="students.xsd"> <student id="1"> <name> <firstname>ivan</firstname> <lastname>ivanov</lastname> </name> <faculty>fksis</faculty> <address> <country>belarus</country> <city>minsk</city> <street>rokossovskogo 24</street> </address> <phone>6677088</phone> </student> <student id="2"> <name> <firstname>petr</firstname> <lastname>petrov</lastname> </name> <faculty>fre</faculty> <address> <country>belarus</country> <city>mogilev</city> <street>leninskaya 25</street> </address> <phone>5467043</phone> </student> </students>
in students.xml have error (invalid content found starting element 'student'. no child element expected @ point.) in part:
<student id="2"> <name> <firstname>petr</firstname> <lastname>petrov</lastname> </name> <faculty>fre</faculty> <address> <country>belarus</country> <city>mogilev</city> <street>leninskaya 25</street> </address> <phone>5467043</phone> </student>
what problem? how correct error? thank you!
the way schema set up, defaults allow 1 "student" element in "students". should set maxoccurs unbounded if want 1 or more student elements.
<xs:element name="student" maxoccurs="unbounded">
(maxoccurs defaults 1 if omitted)