Walbury’s Blog

June 4, 2009

The {base type definition} must have an {attribute wildcard}…

Filed under: Programming, Xml Schema — walbury @ 9:11 pm

Yep, that’s what I thought. Ok, a couple of reasons for posting this. One, when I do a search on this I get NO hits, zilch, nada. Am I really the first person in the world to get this error??? It’s an internally coded error message returned from the DotNet2 validation engine. So here’s the message in full:
The {base type definition} must have an {attribute wildcard} and the {target namespace} of the R’s {attribute declaration} must be valid with respect to that wildcard. WTF?!
So as a side-benefit I should now be able to determine if these pages are being crawled by google…
The error resulted from playing around with xsi:type (for the record I’m on Norman Walsh’s opinion; it sucks) but hey, it exists so deal with it I guess.
Ok, let’s see how well wordpress handles code.
Here’s the main xsd testDerived.xsd:

<?xml version="1.0" encoding="UTF-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
	<xs:include schemaLocation="testDerived_Inc.xsd"/>
	<xs:element name="data" type="POCD_MT000040.InfrastructureRoot.typeId">
		<xs:annotation>
			<xs:documentation>Derivation test</xs:documentation>
		</xs:annotation>
	</xs:element>
	<xs:complexType name="POCD_MT000040.InfrastructureRoot.typeId">
		<xs:complexContent>
			<xs:restriction base="baseType">
				<xs:sequence>
					<xs:element ref="elemA" minOccurs="0" maxOccurs="3"/>
				</xs:sequence>
				<xs:attribute name="root" type="xs:string" use="required" fixed="2.16.840.1.113883.1.3"/>
				<xs:attribute name="extension" type="xs:string" use="required"/>
			</xs:restriction>
		</xs:complexContent>
	</xs:complexType>
	<xs:complexType name="baseType">
		<xs:sequence>
			<xs:element ref="elemA" minOccurs="0" maxOccurs="unbounded"/>
		</xs:sequence>
		<xs:attribute name="root" type="xs:string"/>
		<xs:attribute name="extension" type="xs:string"/>
	</xs:complexType>
	<xs:complexType name="POCD_MT000040.InfrastructureRoot.typeId_TEST_P">
		<xs:complexContent>
			<xs:restriction base="POCD_MT000040.InfrastructureRoot.typeId">
				<xs:sequence>
					<xs:element ref="elemA" minOccurs="0"/>
				</xs:sequence>
				<xs:attribute name="displayable" use="prohibited"/>
			</xs:restriction>
		</xs:complexContent>
	</xs:complexType>
	<xs:complexType name="POCD_MT000040.InfrastructureRoot.typeId_TEST">
		<xs:complexContent>
			<xs:extension base="POCD_MT000040.InfrastructureRoot.typeId">
				<xs:attribute name="newOne" type="xs:string" use="optional"/>
			</xs:extension>
		</xs:complexContent>
	</xs:complexType>
	<xs:complexType name="POCD_MT000040.InfrastructureRoot.typeId_TEST_2">
		<xs:complexContent>
			<xs:restriction base="POCD_MT000040.InfrastructureRoot.typeId_TEST">
				<xs:sequence>
					<xs:element ref="elemA" minOccurs="0" maxOccurs="2"/>
				</xs:sequence>
				<xs:attribute name="newOne" type="xs:string" use="required"/>
			</xs:restriction>
		</xs:complexContent>
	</xs:complexType>
	<xs:complexType name="POCD_MT000040.InfrastructureRoot.typeId_TEST_3">
		<xs:complexContent>
			<xs:extension base="POCD_MT000040.InfrastructureRoot.typeId_TEST_2">
				<xs:attribute name="newTwo" type="xs:string" use="optional"/>
			</xs:extension>
		</xs:complexContent>
	</xs:complexType>
	<xs:complexType name="POCD_MT000040.InfrastructureRoot.typeId_TEST_4">
		<xs:complexContent>
			<xs:restriction base="POCD_MT000040.InfrastructureRoot.typeId_TEST_3">
				<xs:sequence>
					<xs:element ref="elemA" minOccurs="0"/>
				</xs:sequence>
				<xs:attribute name="newTwo" type="xs:string" use="required"/>
			</xs:restriction>
		</xs:complexContent>
	</xs:complexType>
</xs:schema>

And here’s the include testDerived_Inc.xsd:

<?xml version="1.0" encoding="UTF-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
	<xs:element name="elemA" type="xs:string"/>
</xs:schema>

And here’s the instance:

<?xml version="1.0" encoding="UTF-8"?><data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\Inetpub\wwwroot\XmlEdit\SamplesFinal\HL7\testDerived.xsd" root="2.16.840.1.113883.1.3" extension="???" xsi:type="POCD_MT000040.InfrastructureRoot.typeId_TEST_4" newOne="1" newTwo="2">
	<elemA>blah</elemA>
</data>

Note this instance validates fine in XmlSpy 2005 – yes, I know; not entirely trustworthy.
Stop press – I get the same error in Liquid Xml 2009 (community edition) – I guess XmlSpy is incorrect.
Interesting though – the error text is exactly the same; does this mean Liquid Xml is using the DotNet validator, or even written in DotNet?!!
Surely someone else in the world has had this error…

For those of you familiar with HL7 – you have my commiserations :), yes my starting point was one of CDA’s complex types.

Thought I’d do some more investigation – Liquid Xml gives an error on the line

<xs:attribute name="displayable" use="prohibited"/>

so I’ve removed it and the schemas validate ok (or seems to – still has an error listed?)
Next step; choose create xml instance and it auto-generates an instance as per below:

<?xml version="1.0" encoding="utf-8"?>
<!-- Created with Liquid XML Studio - FREE Community Edition 7.1.1.1206 (http://www.liquid-technologies.com) -->
<data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\Inetpub\wwwroot\XmlEdit\SamplesFinal\HL7\testDerived.xsd" 
   xsi:type="POCD_MT000040.InfrastructureRoot.typeId_TEST_P" root="2.16.840.1.113883.1.3" extension="string">
   <elemA>string</elemA>
</data>

Alas, still invalid… So I guess I can’t trust Liquid Xml either!! 😦
Also unsure why it has decided to use the type POCD_MT000040.InfrastructureRoot.typeId_TEST_P; maybe because it was the first derived one encountered?
Swapped POCD_MT000040.InfrastructureRoot.typeId_TEST_P with POCD_MT000040.InfrastructureRoot.typeId_TEST and instance below now includes the last type!

<?xml version="1.0" encoding="utf-8"?>
<!-- Created with Liquid XML Studio - FREE Community Edition 7.1.1.1206 (http://www.liquid-technologies.com) -->
<data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\Inetpub\wwwroot\XmlEdit\SamplesFinal\HL7\testDerived.xsd" 
xsi:type="POCD_MT000040.InfrastructureRoot.typeId_TEST_4" newTwo="string" newOne="string" root="2.16.840.1.113883.1.3" extension="string">
  <elemA>string</elemA>
</data>

Unsure what it’s doing here. Still invalid though.
Schema is still giving a error (although nothing underlined and still generates an instance – shouldn’t generate xml if xsd is screwed?)
Nothing for it; strip it down and add each bit one at a time.
Summary – added each derivation singly and is now OK! NOTHING HAS CHANGED – maybe a caching issue with LiquidXml??
This appears to be the case as the removal of the “prohibited” line is literally the only difference…

Auto-generated a valid xml instance as per below:

<?xml version="1.0" encoding="utf-8"?>
<!-- Created with Liquid XML Studio - FREE Community Edition 7.1.1.1206 (http://www.liquid-technologies.com) -->
<data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\Inetpub\wwwroot\XmlEdit\SamplesFinal\HL7\testDerived_Min.xsd" 
  xsi:type="POCD_MT000040.InfrastructureRoot.typeId_TEST_2" newOne="string" root="2.16.840.1.113883.1.3" extension="string">
  <elemA>string</elemA>
</data>

For the record the original error indicates that you have added a new attribute using restriction (not extension) so is invalid.

Final (valid) main schema is now:

<?xml version="1.0" encoding="UTF-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
	<xs:include schemaLocation="testDerived_Inc.xsd"/>
	<xs:element name="data" type="POCD_MT000040.InfrastructureRoot.typeId">
		<xs:annotation>
			<xs:documentation>Derivation test</xs:documentation>
		</xs:annotation>
	</xs:element>
	<xs:complexType name="POCD_MT000040.InfrastructureRoot.typeId">
		<xs:complexContent>
			<xs:restriction base="baseType">
				<xs:sequence>
					<xs:element ref="elemA" minOccurs="0" maxOccurs="3"/>
				</xs:sequence>
				<xs:attribute name="root" type="xs:string" use="required" fixed="2.16.840.1.113883.1.3"/>
				<xs:attribute name="extension" type="xs:string" use="required"/>	
				<xs:attribute name="displayable" use="prohibited"/>			
			</xs:restriction>
		</xs:complexContent>
	</xs:complexType>
	<xs:complexType name="baseType">
		<xs:sequence>
			<xs:element ref="elemA" minOccurs="0" maxOccurs="unbounded"/>
		</xs:sequence>
		<xs:attribute name="root" type="xs:string"/>
		<xs:attribute name="extension" type="xs:string"/>
		<xs:attribute name="displayable" use="optional"/>
	</xs:complexType>	
	<xs:complexType name="POCD_MT000040.InfrastructureRoot.typeId_TEST">
		<xs:complexContent>
			<xs:extension base="POCD_MT000040.InfrastructureRoot.typeId">
				<xs:attribute name="newOne" type="xs:string" use="optional"/>
			</xs:extension>
		</xs:complexContent>
	</xs:complexType>		
	<xs:complexType name="POCD_MT000040.InfrastructureRoot.typeId_TEST_P">
		<xs:complexContent>
			<xs:restriction base="POCD_MT000040.InfrastructureRoot.typeId">
				<xs:sequence>
					<xs:element ref="elemA" minOccurs="0"/>
				</xs:sequence>
			</xs:restriction>
		</xs:complexContent>
	</xs:complexType>	
	<xs:complexType name="POCD_MT000040.InfrastructureRoot.typeId_TEST_2">
		<xs:complexContent>
			<xs:restriction base="POCD_MT000040.InfrastructureRoot.typeId_TEST">
				<xs:sequence>
					<xs:element ref="elemA" minOccurs="0" maxOccurs="2"/>
				</xs:sequence>
				<xs:attribute name="newOne" type="xs:string" use="required"/>
			</xs:restriction>
		</xs:complexContent>
	</xs:complexType>	
	<xs:complexType name="POCD_MT000040.InfrastructureRoot.typeId_TEST_3">
		<xs:complexContent>
			<xs:extension base="POCD_MT000040.InfrastructureRoot.typeId_TEST_2">
				<xs:attribute name="newTwo" type="xs:string" use="optional"/>
			</xs:extension>
		</xs:complexContent>
	</xs:complexType>	
	<xs:complexType name="POCD_MT000040.InfrastructureRoot.typeId_TEST_4">
		<xs:complexContent>
			<xs:restriction base="POCD_MT000040.InfrastructureRoot.typeId_TEST_3">
				<xs:sequence>
					<xs:element ref="elemA" minOccurs="0"/>
				</xs:sequence>
				<xs:attribute name="newTwo" type="xs:string" use="required"/>
			</xs:restriction>
		</xs:complexContent>
	</xs:complexType>
</xs:schema>

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Create a free website or blog at WordPress.com.