GUID simple Type

I received an external schema with the following type in it:

<xs:element minOccurs="1" maxOccurs="1" name="Id" type="wsdl:guid" />

There also was a reference to:

 <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://microsoft.com/wsdl/types/">
<xs:import namespace="http://microsoft.com/wsdl/types/" />

However the build failed with:
Error 6 Type ‘http://microsoft.com/wsdl/types/:guid’ is not declared, or is not a simple type. D:ExternalSchemasschemaname.xsd ExternalSchemas

I came ac cross a few posts for handling guids in schema’s:
http://www.level533.com/2011/01/how-to-define-guid-properties-in-xsd-schemas-for-generating-poco-classes/
http://msdn.microsoft.com/en-us/library/office/aa203890(v=office.11).aspx

The simplest way to solve this is to add a schema with the guid type in it and then add the location in the import. So add a schema:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:tns="http://microsoft.com/wsdl/types/" elementFormDefault="qualified" targetNamespace="http://microsoft.com/wsdl/types/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="guid">
<xs:annotation>
<xs:documentation xml:lang="en">
The representation of a GUID, generally the id of an element.
</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:pattern value="[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}" />
</xs:restriction>
</xs:simpleType>
</xs:schema>

Then add the location to the import in the first schema:

<xs:import namespace="http://microsoft.com/wsdl/types/" schemaLocation="SimpleImport.xsd"/>

Builds!

Leave a Reply