Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XML
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 26th, 2008, 03:52 PM
Authorized User
Join Date: Oct 2006
Location: , , .
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default What is '{no name}' is 'empty' in complex type?

  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:restriction base="BoxType">
      <xs:attribute name="type" default="Big">
        <xs:enumeration value="Big"/>
        <xs:enumeration value="Small"/>

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

Appreciate any help.
Reply With Quote
  #2 (permalink)  
Old March 26th, 2008, 04:03 PM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts

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:

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

/- Sam Judson : Wrox Technical Editor -/
Reply With Quote
  #3 (permalink)  
Old March 26th, 2008, 04:35 PM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts

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
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 11:52 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.