1

I try to define some xsd scheme for my xml files.

The xml structure is something like

<?xml version="1.0" encoding="UTF-8"?>
<product name="abc" xmlns="http://example.org/productMetadata.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://example.org/productMetadata.xsd productMetadata.xsd">
    <metainf />
</product>

(root tag with some defined attribute "name" and some nested tags as in the example "metainf")

My approach in defining the xsd looks like

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://example.org/productMetadata.xsd" xmlns="http://example.org/productMetadata.xsd">

    <xsd:element name="product">
        <xsd:complexType>
            <xsd:all>
                <xsd:element type="xsd:string" name="metainf" />
            </xsd:all>
            <xsd:attribute type="xsd:string" name="name" />
        </xsd:complexType>
    </xsd:element>

</xsd:schema>

Nevertheless, I'm not able to validate the xml against the xsd.

Depending on the validator (I used java, a web-app and eclipse) I get the following failure message.

Invalid content was found starting with element 'metainf'. One of '{metainf}' is expected.

or

Cvc-complex-type.2.4.a: Invalid Content Was Found Starting With Element 'metainf'. One Of '{metainf}' Is Expected., Line '5', Column '13'.

Anyone some hint, what's wrong with my xsd or xml.

titan_cb
  • 63
  • 1
  • 8

1 Answers1

2

Just add elementFormDefault="qualified" on the xsd:schema declaration, like so:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    elementFormDefault="qualified"
    targetNamespace="http://example.org/productMetadata.xsd" xmlns="http://example.org/productMetadata.xsd">

As per the documentation of the elementFormDefault attribute:

The form for elements declared in the target namespace of this schema. The value must be "qualified" or "unqualified". Default is "unqualified".

  • "unqualified" indicates that elements from the target namespace are not required to be qualified with the namespace prefix.
  • "qualified" indicates that elements from the target namespace must be qualified with the namespace prefix.
Community
  • 1
  • 1
potame
  • 7,597
  • 4
  • 26
  • 33