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

Re: suitable data type to store patterns..

From: Pete Cordell <petexmldev@tech-know-ware.com>
Date: Wed, 9 Jan 2008 21:56:29 -0000
Message-ID: <000901c8530a$8fed4890$a100a8c0@Codalogic>
To: "dave" <ceek63@yahoo.com>, <xmlschema-dev@w3.org>

----- Original Message From: "dave" ----- 
> Am using W3C XML Schema.
> I need to store some pattern values such as
> "[/<*ab^&[[1"  (excluding quotes) in XML. What would
> be the data type for an element which would store such
> values as is?

There's no XSD schema type that allows you to store things like < and & in 
an XML instance in their raw form.  For example, the following would be an 
illegal document:

    <MyElement><&</MyElement>

All you can do is define your type as xs:string (or some restriction 
thereof) and the XML tool or library that you use to interface to your XML 
instance should hopefully do the conversion for you from something like: <& 
to &lt;&amp; and vice versa.

Alternatively your tool (or you if you're rolling your own) may choose to 
store the data in what's called a CDATA Section [1].  This wraps text 
between the tokens <![CDATA[ and ]]>, for example:

        <![CDATA[&]]>

Obviously if your data includes the sequence ]]>, you have to be careful to 
do something like:

        <![CDATA[&]]>]]&gt;<![CDATA[&]]>

for &]]>& (see [2]).

These escaping methods are issues of XML instance well-formedness however, 
which is something a schema can not have no direct impact on.

HTH,

Pete Cordell
Codalogic
Visit http://www.codalogic.com/lmx/ for XML C++ data binding


[1] http://www.w3.org/TR/2006/REC-xml-20060816/#sec-cdata-sect
[2] http://www.w3.org/TR/2006/REC-xml-20060816/#syntax 
Received on Wednesday, 9 January 2008 21:57:28 GMT

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