Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 26th, 2008, 03:52 PM
Authorized User
 
Join Date: Oct 2006
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default What is '{no name}' is 'empty' in complex type?

Hi.
  I have the following snippet of XML:
  <Box type="Big"><Pencil>My</Pencil></Box>

  I get the following error message when I try to validate the XML against the schema:
  The content of complex type '{no name}' is 'empty'. This forbids any content for element 'Box'.

  Does anybody know why? Please help.

The schema I used to validate the XML is the following:
<xs:element name="Box">
  <xs:complexType>
    <xs:restriction base="BoxType">
      <xs:attribute name="type" default="Big">
        <xs:enumeration value="Big"/>
        <xs:enumeration value="Small"/>
      </xs:attribute>
    </xs:restriction>
  </xs:complexType>
</xs:element>

<xs:complexType name=BoxType">
  <xs:sequence>
    <xs:element name="Pencil" minOccurs="0" maxOccurs="1">
      <xs:simpleType>
         <xs:restriction base="xs:string">
            <xs:minLength value="1"/>
         </xs:restriction>
      </xs:simpleType>
    </xs:element>
    <xs:element name="Puzzle" minOccurs="0" maxOccurs="1"/>
  </xs:sequence>
</xs:complexType>


Appreciate any help.
 
Old March 26th, 2008, 04:03 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Most schema's I've seen when you are refering to a type you have defined you need to prefix it with a namespace which is declared above. Something like below:

Code:
<xs:schema targetSchemaNamespace="http://test.com" xmlns:ns0="http://test.com">
<xs:element name="Box">
  <xs:complexType>
    <xs:restriction base="ns0:BoxType">
      <xs:attribute name="type" default="Big">
        <xs:enumeration value="Big"/>
        <xs:enumeration value="Small"/>
      </xs:attribute>
    </xs:restriction>
  </xs:complexType>
</xs:element>

...
/- Sam Judson : Wrox Technical Editor -/
 
Old March 26th, 2008, 04:35 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I'm amazed this got as far as validating the source document (what schema processor are you using?). The schema is full of errors that should have been reported before it got anywhere near validating an instance.

Firstly, there's a missing quote in

<xs:complexType name=BoxType">

I mention this only because it gives a rather big clue that the schema you have posted is not the one you actually used, so anything else I say might be nonsense.

This is what Saxon says about your "schema":

Error at xs:restriction on line 6 of file:/c:/temp/test.xsd:
  Element xs:restriction cannot appear here: expected one of {choice, sequence, assert,
  annotation, attributeGroup, anyAttribute, simpleContent, all, attribute, group, complexContent}
Error at xs:enumeration on line 8 of file:/c:/temp/test.xsd:
  Element <xs:enumeration> is not allowed as a child of <xs:attribute>
Error at xs:enumeration on line 9 of file:/c:/temp/test.xsd:
  Element <xs:enumeration> is not allowed as a child of <xs:attribute>
Schema processing failed: 3 errors were found while processing the schema

The BoxType type appears to be OK. The anonymous complex type defined in the Box element declaration is not. If you want to add an attribute, then you need to extend the type, not restrict it. And if the attribute has valid values Big and Small then you need to define a simple type that restricts xs:string with the restriction defining these two enumeration values, and then reference this type from the attribute declaration.


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Web Method Returning a complex Custom data type. saisunil1978 .NET Web Services 0 July 15th, 2008 05:38 AM
Guidelines Item 3: Replace System.Type with Type Ixtlia BOOK: Professional .NET 2.0 Generics 0 August 19th, 2007 04:09 AM
Complex Data Type BSkelding .NET Web Services 5 May 12th, 2005 02:30 PM
unordered elements in complex type mandabear XML 0 September 3rd, 2004 11:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.