0

I am new to XML Schema. So I really dont know what happened. I followed the tutorials and created an valid XML Schema. But it cant find the declaration. That's odd.

The XML file:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<users>
<user><id>1</id><username>thomas01</username><display_name>Thomas Müntzer</display_name><birthday>04.12.1956</birthday><email_address>thomas@muentzer.de</email_address><quota>524288000</quota><quota_used>14727606</quota_used></user>
</users>

The XML Schema:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.infbox_normal.com" xmlns="http://www.infbox_normal.com" elementFormDefault="qualified">

    <xs:element name="users">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="user">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="id" type="xs:integer"/>
                            <xs:element name="username" type="xs:string"/>
                            <xs:element name="display_name" type="xs:string"/>
                            <xs:element name="birthday" type="xs:string"/>
                            <xs:element name="email_address">
                                <xs:simpleType>
                                    <xs:restriction base="xs:string">
                                        <xs:pattern value="/^\S+@\S+\.\S+$/"/>
                                    </xs:restriction>
                                </xs:simpleType>
                            </xs:element>
                            <xs:element name="quote" type="xs:integer"/>
                            <xs:element name="quote_used" type="xs:integer"/>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

    </xs:schema> 

The error meg:

Error - Line 2, 8: org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 8; cvc-elt.1: Cannot find the declaration of element 'users'.

I use this to validate the XML Schema.

lexicore
  • 42,748
  • 17
  • 132
  • 221
JACK M
  • 2,627
  • 3
  • 25
  • 43

1 Answers1

1

Your XSD defines a target namespace http://www.infbox_normal.com but your XML has no namespaces.

lexicore
  • 42,748
  • 17
  • 132
  • 221
  • But I find a related question. How can you explain that in that example the same test can be passed? http://stackoverflow.com/questions/20949846/xml-validation-against-xsd-in-php-libxml In that example there is no namespace in that validated xml file. – JACK M Dec 09 '14 at 14:26
  • @JACKM And there's also no `targetNamespace` in the schema. – lexicore Dec 09 '14 at 14:29
  • Look at the webpage I gave you in the first comment. And then paste and copy the xml file and the xml schema to http://www.utilities-online.info/xsdvalidation. The xml file does not have any namespace info. But the validation can be passed. – JACK M Dec 09 '14 at 14:30
  • Oh, yes you are right. Thank you. I am really confused about some concepts. – JACK M Dec 09 '14 at 14:31