aspose file tools*
The moose likes Web Services Certification (SCDJWS/OCEJWSD) and the fly likes Namespace Declaration !! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Services Certification (SCDJWS/OCEJWSD)
Bookmark "Namespace Declaration !!" Watch "Namespace Declaration !!" New topic
Author

Namespace Declaration !!

Marco Lombardo
Ranch Hand

Joined: Jul 05, 2005
Posts: 71
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


Team Leader<br />SCJP, SCBCD , SCDJWS, Oracle WebLogic, IBM WebSphere e IBM FileNet Certified<br /> <br /><a href="http://www.marcolombardo.it" target="_blank" rel="nofollow">http://www.marcolombardo.it</a>
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
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 ]

SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Marco Lombardo
Ranch Hand

Joined: Jul 05, 2005
Posts: 71
Please, explain better.
Is it legal to omit mh:?
Thanks.
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Namespace Declaration !!