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 June 27th, 2006, 11:32 AM
Registered User
 
Join Date: Jul 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Schema Complex element with restriction problem

I am trying to write a schema for an element with two attributes.

<Data compression="gzip" encoding="base64">some xml </Data>

I have to make sure in the schema that value of data (represented by "some xml") should be atleast 1 character in length. How can I define this in schema. Please help. I tried using the code given below, but it doesnt work.

<xs:element name="Data">
    <xs:complexType mixed="true">
       <xs:simpleContent>
            <xs:restriction/>
             <xs:restriction base="xs:string">
            <xs:minLength value="1" />
            </xs:restriction>
         <xs:attribute name="compression" use="required" type="compressiontype"/>
         <xs:attribute name="encoding" use="required" type="encodingtype"/>
      </xs:simpleContent>
    </xs:complexType>
</xs:element>



These are the errors I get:

The BASE attribute must be specified for the RESTRICTION or EXTENSION element
Attribute 'encoding' is not declared for element 'Data'
Attribute 'compression' is not declared for element 'Data'

Any help on this will be greatly appreciated.

 
Old June 27th, 2006, 11:45 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

First define a simple type that is a restriction of xs:string with a minLength. Then define a complex type with simple content that extends this with attributes:

<xs:element name="shoesize">
  <xs:complexType>
    <xs:simpleContent>
      <xs:extension base="my:minLengthOneType">
        <xs:attribute name="country" type="xs:string" />
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
</xs:element>

You don't want mixed="true".

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
Problem adding element to the previous element dani1 XSLT 5 September 10th, 2008 01:38 AM
Schema: element is choice of complex types? jkmyoung XML 3 July 18th, 2007 04:54 PM
Complex execCommand() problem Snib Javascript 0 June 15th, 2004 06:08 PM
COMPLEX QUERY PROBLEM nikosdra SQL Server ASP 15 August 4th, 2003 06:17 PM
COMPLEX QUERY PROBLEM nikosdra Classic ASP Databases 2 July 28th, 2003 02:13 PM





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