XML

"Continuous effort - not strength or intelligence - is the key to unlocking our potential." ==> Winston Churchill

Name:
Location: Bangalore, India

Thursday, March 09, 2006

Local elements and targetNamespace

XML Schema

?xml version="1.0"?>
xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://atw.co.in/vis" xmlns:tars="http://atw.co.in/vis"
>

xs:attributeGroup name="Agroup">
xs:attribute name="title" type="xs:string" />
/xs:attributeGroup>

xs:complexType name="NameType" >
xs:sequence>
xs:element name="first" type="xs:string" default="Hi"/>
xs:element name="last" type="xs:string" default="nu"/>
/xs:sequence>
xs:attributeGroup ref="tars:Agroup" />
/xs:complexType>

xs:element name="name" type="tars:NameType"/>
/xs:schema>



XML Document

?xml version="1.0"?>
vis:name
xmlns:vis="http://atw.co.in/vis"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://atw.co.in/vis name2.xsd"
title="Mr.">
vis:first>
vis:last>
/vis:name>

Error:

Element 'first' should be un-qualified
Element 'last' should be un-qualified


Reason for Error:

Look at your XML Schema document and the schema element. elementFormDefault attribute is missing. Hence, this attribute takes the default value, which is unqualified. Because of that, the local elements are not in the targetNamespace.


How to recify these errors?

Replace

-------------------------
vis:first>
vis:last>
--------------------------

With

-------------------------
first>
last>
--------------------------

OR include
elementFormDefault
attribute with "qualified" value in schema element.

XML Schema

?xml version="1.0"?>
xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://atw.co.in/vis" xmlns:tars="http://atw.co.in/vis"
elementFormDefault="qualified">


Why do the local elements do not come under targetNamespace when their parent element is?

That's by definition of the XML Schema recommentations.

0 Comments:

Post a Comment

<< Home