regular expression pattern matching in XML schema

Having trouble installing Oxygen? Got a bug to report? Post it all here.
Susheel

regular expression pattern matching in XML schema

Post 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
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post 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
Post Reply