Page 1 of 1

regular expression pattern matching in XML schema

Posted: Fri Jun 25, 2004 3:00 am
by Susheel
Hi,

I have an element "<foo>" with an attribute "name". The name invariably starts with a prefix ADD_. So all names look like ADD_integers or ADD_floats etc.

I am trying to put a pattern check for this attribute in the XML schema to ensure that the name starts with ADD_.

Can I do this in the schema? If yes,What would be the pattern value for this?

Thanks,
Susheel

Posted: Fri Jun 25, 2004 9:54 am
by george
Hi,

The following schema should be close to what you want:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="foo">
<xs:complexType>
<xs:attribute name="name">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="ADD_.+"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
See http://www.w3.org/TR/xmlschema-2/#rf-pattern for more information about pattern constraints in XML Schema.

Best Regards,
George