Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
| 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 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 October 14th, 2005, 07:30 AM
Registered User
 
Join Date: Oct 2005
Location: Rochester, Kent, United Kingdom.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Schema help!?

I am having a problem with defining an element with simple content that must match a pattern AND have attributes.

I have to use xs:extension on the xs:simpleContent to define attributes, and a xs:restriction on the xs:simpleContent to set my xs:pattern, but I can't seem to do both at the same time! Is this right? What am I doing wrong?

This is fine:
<xs:element name="FILE_COUNT" nillable="false">
  <xs:complexType>
    <xs:simpleContent>
      <xs:extension base="xs:string">
        <xs:attribute name="START_POS" type="xs:string" use="required" fixed="4"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
</xs:element>

And so is this:
<xs:element name="FILE_COUNT" nillable="false">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:pattern value="[0-9]{6}"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

But I need to do something like this..
<xs:element name="FILE_COUNT" nillable="false">
  <xs:complexType>
    <xs:simpleContent>
      <xs:restriction base="xs:string">
         <xs:pattern value="[0-9]{6}"/>
         <xs:attribute name="START_POS" type="xs:string" use="required" fixed="4"/>
      </xs:restriction>
    </xs:simpleContent>
  </xs:complexType>
</xs:element>

Can anyone help?
Thanks,
Nick



 
Old October 14th, 2005, 07:38 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You need to do it in two steps (that is, define an intermediate type which you don't actually need): first an extension to add the attribute, then a restriction to restrict the content. Or vice versa.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old October 14th, 2005, 08:10 AM
Registered User
 
Join Date: Oct 2005
Location: Rochester, Kent, United Kingdom.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the prompt reply Michael!

Was this the sort of thing you had in mind?

<xs:simpleType name="file_count">
 <xs:restriction base="xs:string">
  <xs:pattern value="[0-9]{6}"/>
 </xs:restriction>
</xs:simpleType>

<xs:element name="file_count" nillable="false">
 <xs:complexType>
  <xs:simpleContent>
   <xs:extension base="file_count">
    <xs:attribute name="CLASS" type="xs:string" use="required" fixed="DDM"/>
   </xs:extension>
  </xs:simpleContent>
</xs:complexType>
</xs:element>

If so, that give me other headache of totally rewriting my stuff, as the schema is written programmatically from an Oracle table. :-)

Thanks for your help.
Nick
 
Old October 14th, 2005, 08:24 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Yes, that's the idea.

I'm afraid headaches are a permanent fact of life when writing XML Schemas!



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
Getting schema for database Quick209 ASP.NET 2.0 Basics 0 December 12th, 2006 07:51 PM
Schema to Schema conversion onlyda XSLT 5 March 23rd, 2006 12:25 PM
Schema gabrieldg74 XML 0 August 16th, 2005 05:42 PM
xml schema help allang XML 0 August 19th, 2004 09:58 PM
two databases, one schema defiant SQL Server 2000 3 February 4th, 2004 08:19 PM





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