Monday, August 6, 2007

XML general definition

If you are working with XML, XSD and XSLT don't forget to create and use general definitions in a specific file that you can use in all documents. If you create a XSD with the definitions you want to use.

Example:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.utvecklargodis.com/GeneralDefinitions/1.0" targetNamespace="http://www.utvecklargodis.com/GeneralDefinitions/1.0" elementFormDefault="unqualified" attributeFormDefault="unqualified">
<!-- GUID -->
<xs:simpleType name="GUID">
<xs:annotation>
<xs:documentation>General definition of a GUID</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:pattern value="[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}"/>
</xs:restriction>
</xs:simpleType>
<!-- /GUID -->
</xs:schema>


Then you use the general definition like this:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.utvecklargodis.com/system/2.0" xmlns:ns1="http://www.utvecklargodis.com/system/GeneralDefinitions/1.0" elementFormDefault="unqualified" attributeFormDefault="unqualified">
<xs:import namespace="http://www.utvecklargodis.com/system/GeneralDefinitions/1.0" schemaLocation="./General.xsd"/>
<xs:element name="Objects">
<xs:complexType>
<xs:element name="ObjectID" type="ns1:GUID"/>
</xs:complexType>
</xs:element>
</xs:schema>

No comments: