views:

383

answers:

4

Hi, I have an XML form with an element 0, which is well-formed but not valid. When I try to validate it XMLSpy I get a following error: Nothing is allowed inside empty element 'hidden'. Below is my schema:

<xs:element name="hidden">
    <xs:complexType>
     <xs:attribute name="datatype" type="xs:string" use="optional"/>
     <xs:attribute name="alias" type="xs:string" use="optional"/>
     <xs:attribute name="source" type="xs:string" use="optional"/>
     <xs:attribute name="name" type="xs:string" use="required"/>
     <xs:attribute name="lookup" type="xs:string" use="optional"/>
    </xs:complexType>
</xs:element>

What do I need to add to the above schema to fix this error? Thanx ml

+2  A: 

Your "hidden" element is defined as being empty since you don't have anything in the schema explicitly allowing child elements. I'm assuming you're wanting something like

<hidden *[attributes]*>
   <some_other_element/>
</hidden>

But according to http://www.w3schools.com/Schema/schema_complex_empty.asp you have implicitly defined "hidden" to be empty. You need to define which elements can appear inside "hidden". There are many ways to do this and I suggest starting by reading http://www.w3schools.com/Schema/schema_complex.asp.

Welbog
Thanx a milion weblog. I appreciate your help.
Greg
A: 
Greg
A: 

Thank you Michael and welbog. Unfortunately, I have tried your suggestions and cannot get it right. 0 still throws an error.

Greg
What exactly do you mean by "0"? Are you trying to have an element named 0? Or are you trying to have <hidden>0</hidden>? I don't understand what 0 means in this context.
Welbog
+1  A: 

As welbog noted, you defined a complex empty element. Assuming you want only text within the hidden tag, you could write a schema along theses lines :

<xs:element name="hidden">
  <xs:complexType>
    <xs:simpleContent>
      <xs:extension base="xs:integer">
        <xs:attribute name="datatype" type="xs:string" use="optional"/>
        <xs:attribute name="alias"    type="xs:string" use="optional"/>
        <xs:attribute name="source"   type="xs:string" use="optional"/>
        <xs:attribute name="name"     type="xs:string" use="required"/>
        <xs:attribute name="lookup"   type="xs:string" use="optional"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
</xs:element>

This way, you can have a piece of XML like this one:

<hidden datatype="foo" name="bar">0</hidden>

What is going on here is that I defined "hidden" to be an extension of xs:integer (by the way, you can make it extends any type you want), which means that "hidden" elements are like integers element, but with additional constraints, or in this case with additional attributes.

Luc Touraille
Thanx a lot Luc for your clear explanation!Thanx to Michael and weblog!Best regardsGreg
Greg