N
N
Nikita Shchypylov2017-12-16 01:20:43
XSD
Nikita Shchypylov, 2017-12-16 01:20:43

Why am I getting an org.xml.sax.SAXParseException error when validating xml in xsd?

Error :
Error - Line 13, 16: org.xml.sax.SAXParseException; lineNumber: 13;
columnNumber: 16; cvc-complex-type.2.4.a: Invalid content was found
starting with element 'me:myself'. One of
'{"urn:Test.Namespace":myself}' is expected.

Tested here:
www.utilities-online.info/xsdvalidation

Code:
.xml:

<?xml version="1.0" encoding="utf-8" ?>

    <root
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns="urn:Test.Namespace"
            xsi:schemaLocation="urn:Test.Namespace Laptopy-ShchypylovNikita.xsd"
            xmlns:me="[email protected]"
            xmlns:uek="www.uek.krakow.pl"
    
    >
        <me:myself>
    
            <me:name>Nikita</me:name>
            <me:surename>Shchypylov</me:surename>
            <me:sex>male</me:sex>
            <me:age>19</me:age>
            <me:city>Cracow</me:city>
            <me:homeland>Ukraine</me:homeland>
            <me:course>IT</me:course>
            <me:numer>1</me:numer>
            <me:group>Kr1013</me:group>
        </me:myself>
    
        <uek:copyright >
            Wydzial Zarzadzania, Universytet Economiczny, Krakow
        </uek:copyright>
        <laptopy>
            <laptop type="dell">
                <ekran producent="samsung">
                    wide
                </ekran>
                <card from="intel">
                    very good
                </card>
                <gui>
                    dynamic
                </gui>
                <ram>
                    8
                </ram>
                <material made="in_china">
                    steel
                </material>
            </laptop>
            <laptop type="samsung">
                <ekran producent="samsung">
                    wide
                </ekran>
                <card from="intel">
                    good
                </card>
                <gui>
                    dynamic
                </gui>
                <ram>
                    8
                </ram>
                <material made="in_china">
                    steel
                </material>
            </laptop>
            <laptop type="dell">
                <ekran producent="samsung">
                    wide
                </ekran>
                <card from="intel">
                    bad
                </card>
                <gui>
                    dynamic
                </gui>
                <ram>
                    8
                </ram>
                <material made="in_china">
                    steel
                </material>
            </laptop>
            <laptop type="razer">
                <ekran producent="samsung">
                    wide
                </ekran>
                <card from="intel">
                    very good
                </card>
                <gui>
                    dynamic
                </gui>
                <ram>
                    8
                </ram>
                <material made="in_china">
                    steel
                </material>
            </laptop>
            <laptop type="dell">
                <ekran producent="samsung">
                    wide
                </ekran>
                <card from="intel">
                    perfect
                </card>
                <gui>
                    dynamic
                </gui>
                <ram>
                    8
                </ram>
                <material made="in_china">
                    wood
                </material>
            </laptop>
            <laptop type="apple">
                <ekran producent="samsung">
                    wide
                </ekran>
                <card from="intel">
                    very good
                </card>
                <gui>
                    dynamic
                </gui>
                <ram>
                    8
                </ram>
                <material made="in_china">
                    steel
                </material>
            </laptop>
            <laptop type="asus">
                <ekran producent="samsung">
                    wide
                </ekran>
                <card from="intel">
                    excellent
                </card>
                <gui>
                    dynamic
                </gui>
                <ram>
                    8
                </ram>
                <material made="in_china">
                    wood
                </material>
            </laptop>
            <laptop type="toshiba">
                <ekran producent="samsung">
                    wide
                </ekran>
                <card from="intel">
                    very good
                </card>
                <gui>
                    dynamic
                </gui>
                <ram>
                    8
                </ram>
                <material made="in_china">
                    steel
                </material>
            </laptop>
            <laptop type="dell">
                <ekran producent="samsung">
                    wide
                </ekran>
                <card from="intel">
                    very good
                </card>
                <gui>
                    dynamic
                </gui>
                <ram>
                    8
                </ram>
                <material made="in_china">
                    steel
                </material>
            </laptop>
            <laptop type="samsung">
                <ekran producent="samsung">
                    wide
                </ekran>
                <card from="intel">
                    very good
                </ca
rd>
dynamic
8
wood
.xsd:
<?xml version="1.0"?>
    

    
    <xsd:schema
            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            targetNamespace="urn:Test.Namespace"
            xmlns="urn:Test.Namespace"
            elementFormDefault="qualified"
            xmlns:me="[email protected]"
            xmlns:uek="www.uek.krakow.pl"
    
    >
    
        <xsd:element name="root">
            <xsd:complexType>
                <xsd:sequence>
                    <xsd:element name="myself" maxOccurs="unbounded"/>
                    <xsd:element name="copyright" maxOccurs="unbounded"/>
                    <xsd:element name="laptopy" maxOccurs="unbounded">
                        <xsd:complexType>
                            <xsd:sequence>
                                <xsd:element name="laptop"
                                             minOccurs="10" maxOccurs="unbounded">
                                    <xsd:complexType>
                                        <xsd:sequence>
                                            <xsd:element name="ekran" type="ekranType"/>
                                            <xsd:element name="card" type="cardType"/>
                                            <xsd:element name="gui" type="xsd:string"/>
                                            <xsd:element name="ram" type="xsd:integer"/>
                                            <xsd:element name="material" type="materialType">
                                            </xsd:element>
                                        </xsd:sequence>
                                        <xsd:attribute name="type" type="xsd:string"/>
                                    </xsd:complexType>
                                </xsd:element>
                            </xsd:sequence>
                        </xsd:complexType>
                    </xsd:element>
                </xsd:sequence>
            </xsd:complexType>
        </xsd:element>
    
        <xsd:complexType name="ekranType">
            <xsd:simpleContent>
                <xsd:extension base="xsd:string">
                    <xsd:attribute name="producent" type="xsd:string"/>
                </xsd:extension>
            </xsd:simpleContent>
        </xsd:complexType>
    
        <xsd:complexType name="cardType">
            <xsd:simpleContent>
                <xsd:extension base="xsd:string">
                    <xsd:attribute name="from" type="xsd:string"/>
                </xsd:extension>
            </xsd:simpleContent>
        </xsd:complexType>
    
        <xsd:complexType name="materialType">
            <xsd:simpleContent>
                <xsd:extension base="xsd:string">
                    <xsd:attribute name="made" type="xsd:string"/>
                </xsd:extension>
            </xsd:simpleContent>
        </xsd:complexType>
    
    </xsd:schema>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question