0

My xml schema and my xml document are both valid and well-formed. But there is still a problem with the correct reference. I looked up a few similar questions but I can`t solve my problem.

Beginning of the xml schema:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com">


<xs:element name="catalog"/>

xml schema example:

<xs:element name="Qstr">
<xs:complexType>
    <xs:sequence>
        <xs:element name="text" type="xs:string"/>
        <xs:element name="a" type="xs:string"/>
        <xs:element name="b" type="xs:string"/>
        <xs:element name="c" type="xs:string"/>
        <xs:element name="d" type="xs:string"/>
    </xs:sequence>
</xs:complexType>

beginning of xml document:

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



<catalog xmlns="http://www.w3schools.com"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.w3schools.com   file:///home/n/workspace/webprog1/WebContent/schema.xml">

<Qstr>
    <text>random question?</text>
    <a>asdfasd</a>
    <b>ertwetrewt</b>
    <c>ghkghk</c>
    <d>xcvbxcbbx</d>
</Qstr>

Error message:

 Invalid content was found starting with element '{"http://www.w3schools.com":text}'. One of '{text}' is expected.

1 Answers1

1

The default value for elementFormDefault is unqualified. Because you're using a default namespace with <catalog>, all child elements will also take on the same namespace, instead of no namespace (which is what you want).

E.g. see here for more info.

It will probably (you didn't paste the full XSD) work if you change to something like:

<myns:catalog xmlns:myns="http://www.w3schools.com"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.w3schools.com   file:///home/n/workspace/webprog1/WebContent/schema.xml">

<myns:Qstr>
    <text>random question?</text>
    <a>asdfasd</a>
    <b>ertwetrewt</b>
    <c>ghkghk</c>
    <d>xcvbxcbbx</d>
</myns:Qstr>
Community
  • 1
  • 1
Scott Kurz
  • 4,985
  • 1
  • 18
  • 40
  • Thanks for the response, I set elementFormDefault to "qualified", now I`m getting no errors. My actual problem(transforming the xml file to html) isn`t solved yet, but I already asked about that in another question. – schaeffer.heng Apr 19 '16 at 15:25
  • OK, if it helped please accept or at least vote up the answer. Thanks. – Scott Kurz Apr 19 '16 at 21:47