Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Namespace Declaration !!

 
Marco Lombardo
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Giving this schema I have two questions.
Is it mandatory to declare a qualified name mh:USAddress in the element shipAddress and USAddress of PurchaseOrder??
If I declare only type="USAddress" the schema does take the targetNamespace?

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:mh="http://www.Monson-Haefel.com/jwsbook"
targetNamespace="http://www.Monson-Haefel.com/jwsbook" >

<complexType name="PurchaseOrder">

<sequence>
<element name="accountName" type="string" />
<element name="accountNumber" type="unsignedShort" />
<element name="shipAddress" type="mh:USAddress" />
<element name="billAddress" type="mh:USAddress" />
<element name="book" type="mh:Book" />
<element name="total" type="float" />
</sequence>

<attribute name="orderDate" type="date"/>

</complexType>

<complexType name="USAddress">
<sequence>
<element name="name" type="string" />
<element name="street" type="string" />
<element name="city" type="string" />
<element name="state" type="string" />
<element name="zip" type="string" />
</sequence>
</complexType>

<complexType name="Book">
<sequence>
<element name="title" type="string" />
<element name="quantity" type="unsignedShort" />
<element name="wholesale-price" type="float" />
</sequence>
</complexType>

</schema>

Thanks
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens if you derive an instance document from this schema and try to validate it against both alternatives of the schema ?
[ October 11, 2006: Message edited by: Valentin Crettaz ]
 
Marco Lombardo
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please, explain better.
Is it legal to omit mh:?
Thanks.
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for the delay, Marco !

No, you have to put that prefix there otherwise the parser will not be able to find the USAddress type. The targetNamespace property only indicates in which namespace the newly defined types (PurchaseOrder, USAddress, Book) will be located. Thus, in order to use one of those types (as attribute or element type) you have to tell in which namespace to find it, and this is done by using the namespace prefix.

If you don't include the prefix, the element will be searched for in the default namespace (the one defined by xmlns="") and in this case it is the XML Schema namespace. The parser will not be able to find the USAddress element in the XML Schema namespace.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic