• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XMLSchema - Global Attribute Declaration

 
Naren Chivukula
Ranch Hand
Posts: 577
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

It's always been confusing to go through the XML Schma namespaces, prefixes and qualification. With so much of effort and expert write-ups in this forum, I hope I've come to know most of the concepts. But, few things are contradicting my knowledge on this area.

For example, in RMH (P.Np 52) it has been mentioned that
"The default namespace doesn't apply to global attributes; global attributes must always be prefixed."

But listing 3-18 on page 55, seems to be valid against the schema defined in listing 3-15 though there is NO prefix for the global attribute orderDate (to qualify). I'm lost here. Can somebody please give me the reason for the listing 3-18 valid still!?

Thanks and Regards,
Naren
[ July 06, 2008: Message edited by: Naren Chivukula ]
 
Dhanasekaran Krishnasamy
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,
I would like to see and try to answer your query but i dont have the book you are referring to. May be paste some snippet if possible.
 
Naren Chivukula
Ranch Hand
Posts: 577
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Here you go...

Listing 3-6 An Instance of the Schema in Listing 3-5
<?xml version="1.0" encoding="UTF-8"?>
<po urchaseOrder orderDate="2003-09-22"
xmlns o="http://www.Monson-Haefel.com/jwsbook">
<accountName>Amazon.com</accountName>
<accountNumber>923</accountNumber>
<shipAddress>
<name>AMAZON.COM</name>
<street>1850 Mercer Drive</street>
<city>Lexington</city>
<state>KY</state>
<zip>40511</zip>
</shipAddress>
<billAddress>
<name>Amazon.com</name>
<street>1516 2nd Ave</street>
<city>Seattle</city>
<state>WA</state>
<zip>90952</zip>
</billAddress>
<book>
<title>J2EE Web Services</title>
<quantity>300</quantity>
<wholesale-price>24.99</wholesale-price>
</book>
<total>8997.00</total>
</po urchaseOrder>

Courtesy: J2EE Web Services by Richard Monson Haefel

Thanks and Regards,
Naren
-----------
SCJP - 93%
SCDJWS - 86%
 
Dhanasekaran Krishnasamy
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The statement "The default namespace doesn't apply to global attributes; global attributes must always be prefixed." makes sense when you mix two namespaces.
for example one.xsd
...
<element name="FirstElement" type="mh:MyCompType1"/>
<complexType name="MyCompType1">
<all>
<element name="element1" type="string"/>
<element name="element2" type="long"/>
<element name="element3" type="float" minOccurs="0"/>
</all>
<attribute ref="mh:MyAttri"/>
</complexType>
<attribute name="MyAttri" type="string" default="Attribute"/>
...

2nd.xsd
...
<element name="book">
<complexType>
<sequence>
<element name="title" type="string"/>
<element name="quantity" type="unsignedShort"/>
<element name="wholesale-price" type="float"/>
<element ref="mh:FirstElement"/></sequence>
</complexType>
</element>
...

when i create a xml instance doc from 2nd.xsd it comes out to be
...
<ns1:book xmlns:ns1="http://dhana.com/dhanasekaran">
<ns1:title>String</ns1:title>
<ns1:quantity>65535</ns1:quantity>
<ns1:wholesale-price>3.14159E0</ns1:wholesale-price>
<mh:FirstElement mh:MyAttri="Attribute" xmlns:mh="http://dhana.com/dhana">
<mh:element1>String</mh:element1>
<element2>2147483647</element2>
</mh:FirstElement>
</ns1:book>
...

here I cant remove the mh in mh:MyAttri though mh can be removed from element1 and 2(already done).

I hope you understand now. the unqualified attributes are either local attributes or imported from docs with no namespace.

Ref: Oreilly XMl Schema.
[ July 13, 2008: Message edited by: Dhanasekaran Krishnasamy ]
 
Naren Chivukula
Ranch Hand
Posts: 577
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.

But, I'm NOT talking about local attributes. But specifically on global attributes. For example in your sample, attributes could have used for <ns1:book>.

Kind Regards,
Naren
 
Dhanasekaran Krishnasamy
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have explained about the global attribute only, that is MyAttri.

In your example the orderDate is not a global attribute, global meaning its defined as a global a attribute which can be used in other schema docs also with importing.

[ July 14, 2008: Message edited by: Dhanasekaran Krishnasamy ]
[ August 19, 2008: Message edited by: Dhanasekaran Krishnasamy ]
 
Vignesh Murali Natarajan
Ranch Hand
Posts: 65
Firefox Browser Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Naren,
You have mistook 'orderDate' attribute as a global attribute. It is not. Look at listing 3-13 that shows the schema for purchaseOrder element. In that schema, orderDate has been declared as an attribute of purchaseOrder. If it were a global attribute, it would have been declared outside the complexType element that defines purchaseOrder element. By saying that the XML instance in 3-18 is valid for XML schema in 3-15, the author casts focus only on the address element. Listing 3-15 does not show the entire schem doc. Ellipsis (...) replaces the schema for purchaseOrder.

To summarize, orderDate attribute is local to purchaseOrder element and is not global (Listing 3-13)
ThanQ,
Vignesh Murali N
[ July 17, 2008: Message edited by: Vignesh Murali Natarajan ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic