W3C home > Mailing lists > Public > xmlschema-dev@w3.org > January 2008

RE: Forcing content according to attribute

From: Michael Kay <mike@saxonica.com>
Date: Wed, 23 Jan 2008 09:23:28 -0000
To: "'Papalagi Pakeha'" <papalagi.pakeha@gmail.com>, <xmlschema-dev@w3.org>
Message-ID: <00d401c85da1$9d3652c0$6501a8c0@turtle>

This is the classic use case for "conditional type assignment" which is a
feature in XSDL 1.1.

With version 1.0, the only way to achieve it is by naming the attribute
xsi:type.

Michael Kay
http://www.saxonica.com/
 

> -----Original Message-----
> From: xmlschema-dev-request@w3.org 
> [mailto:xmlschema-dev-request@w3.org] On Behalf Of Papalagi Pakeha
> Sent: 23 January 2008 00:29
> To: xmlschema-dev@w3.org
> Subject: Forcing content according to attribute
> 
> 
> hello,
> 
> in our xml documents we use <Attachment> tag to specify, 
> well, attachments to these documents. something like:
> 
> <Doc>
> <Title>xyz</Title>
> ....
> <Attachment type="logo" 
> format="url">http://some.url/logo.jpg</Attachment>
> <Attachment type="token" format="inline">U29tZVRoaW5nCg==</Attachment>
> <Attachment type="data" format="filename">local.file.bin</Attachment>
> </Doc>
> 
> Is there any way in XSD to enforce:
> - base64 content for format="inline",
> - URL content when format="url", and
> - non-URL when format="filename"
> ?
> 
> For now I have:
> 
>   <xs:element name="Attachment">
>     <xs:complexType>
>       <xs:simpleContent>
>         <xs:extension base="xs:string">
>           <xs:attribute name="format" use="required">
>             <xs:simpleType>
>               <xs:restriction base="xs:string">
>                 <xs:enumeration value="inline"/>
>                 <xs:enumeration value="filename"/>
>                 <xs:enumeration value="url"/>
>               </xs:restriction>
>             </xs:simpleType>
>           </xs:attribute>
>           <xs:attribute name="type" use="required">
>             <xs:simpleType>
>               <xs:restriction base="xs:string">
>                 <xs:enumeration value="logo"/>
>                 <xs:enumeration value="token"/>
>                 <xs:enumeration value="data"/>
>               </xs:restriction>
>             </xs:simpleType>
>           </xs:attribute>
>         </xs:extension>
>       </xs:simpleContent>
>     </xs:complexType>
>   </xs:element>
> 
> that works well but accepts any "xs:string" for content and 
> not enforcing URL/non-URL/base64.
> 
> can anyone throw some hints on how to achieve the link 
> between format and content please?
> 
> thanks!
> 
> papa
> 
> 
Received on Wednesday, 23 January 2008 09:23:38 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:15:01 GMT