aspose file tools*
The moose likes Product and Other Certifications and the fly likes How to use elementFormDefault and attributeFormDefault? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Product and Other Certifications
Bookmark "How to use elementFormDefault and attributeFormDefault?" Watch "How to use elementFormDefault and attributeFormDefault?" New topic
Author

How to use elementFormDefault and attributeFormDefault?

jim yin
Ranch Hand

Joined: Aug 15, 2002
Posts: 111
Hi, ranchers.
I am not very clear how to use these two attributes in Schemas. Could anyone give some examples about when and how to use them? Thanks.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi Jim,
Roger L. Costello explains this topic very well in his Power point presentation on XML Schema's.
You can download it from the Website www.XFront.com
Link
[Added Comment :]
Check the 2nd PPT
[ September 09, 2002: Message edited by: Vinayak Gajarajan ]
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1180
Jim,
Please have a look at the XML Bible
Towards the end of the chapter it says -
"The third attribute, elementFormDefault, has the value qualified. This means that the elements being described in this document are in fact in a namespace; specifically they're in the target namespace given previously by the targetNamespace attribute. This does not mean that the elements being modeled necessarily have prefixes, merely that they are in some namespace.
Finally, the fourth attribute, attributeFormDefault, has the value unqualified. This means that the attributes described by this schema are not in a namespace."

You can also look at thespecification itself which says the following about the element declaration -
"If form is present and its -actual value- is qualified, or if form is absent and the -actual value- of elementFormDefault on the <schema> ancestor is qualified, then the -actual value- of the targetNamespace [attribute] of the parent <schema> element information item, or -absent- if there is none, otherwise -absent-."

Cheers,
Dan


William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
jim yin
Ranch Hand

Joined: Aug 15, 2002
Posts: 111
Thanks, guys. Your tips are very helpful.
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Originally posted by Dan Drillich:
Jim,
Finally, the fourth attribute, attributeFormDefault, has the value unqualified. This means that the attributes described by this schema are not in a namespace."

I feel this is wrong. attributeFormDefault set to "unqualified" doesn't means that they are not in a namespace.
As explained in Roger Slides,its will just act as a switch to hide or expose the namespace qualifiers in the instance document.
Regards
Balaji


Spritle Software Blogs
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
And this true for elementFormDefault as well.
Originally posted by Balaji Loganathan:

Balaji
jim yin
Ranch Hand

Joined: Aug 15, 2002
Posts: 111
unqualified attributes are in the null namespace, rather than the default namespace. Does "null namespace" means "no namespace"?
[ September 10, 2002: Message edited by: jim yin ]
Jayadev Pulaparty
Ranch Hand

Joined: Mar 25, 2002
Posts: 662
I really don't understand the relevance of this switch elementFormDefault (qualified/unqualified)
When we are defining an element for a target namespace in a schema document and tieing up that schema with our instance document, any attempt to use the element should always be coupled with the namespace (by prefix or otherwise)???
I always believe in examples, so let us look at a simple example -
In the schema definition (file - book.xsd),
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.books.org"
targetnamespace="http://www.books.org"
elementFormDefault="qualified">
<!-- just a simple book element -->
<xsd:element name="Book">
<xsd:complexType>
<xsd:sequence>
<xsd:any/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
In the instance document -
<?xml version="1.0"?>
<Book xmlns="http://www.books.org"
xmlns:xsi="http://www.w3.ogr/2001/XMLSchema-instance"
xmlns:some="http://www.other.org"
xsi:schemaLocation="http://www.books.org
book.xsd
"http://www.other.org
someother.xsd"
>
<!-- Here i'm using the book element of -->
<!-- http://www.books.org namespace -->
<!-- tied up to book.xsd schema -->
<!-- Let us assume that elementFormDefault is -->
<!-- qualified in someother.xsd -->
<some:someotherElement/>
</Book>
Is there any other way i can refer to the someotherElement without qualifying it with some:??
Hence coming back to full-circle, what is the relevance of the elementFormDefault.
All these things are totally mixed up in my head Anyone please clarify........
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1180
Balaji,
You said -
As explained in Roger Slides, it will just act as a switch to hide or expose the namespace qualifiers in the instance document.

Where did you get it from?
I'm looking at Rogers' xml-schemas1 PowerPoint presentation and he says there -
elementFormDefault="qualified" -
This is a directive to any instance documents which conform to this schema:
Any elements used by the instance document which were declared in this schema must be namespace qualified.

So, it seems to me that Roger confirms here the 'XML Bible' explanation.
Cheers,
Dan
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Hi Dan..
I was refering from this document http://www.xfront.com/HideVersusExpose.pdf
Now you can check against XML Bible.
Regards
Balaji
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Originally posted by Jayadev Pulaparty:
Is there any other way i can refer to the someotherElement without qualifying it with some:??

Yes it possible,with the help of complexType or simpleType or elements or attribute binding.
For example: Assume that you have a complexType called someotherElement in someother.xsd, In your books.xsd schema create a element called "otherElement" and refer it to some:someotherElement,now the instance document element doesn't to carry the qualifier "some:".

Hence coming back to full-circle, what is the relevance of the elementFormDefault.
All these things are totally mixed up in my head Anyone please clarify........

Ok Relax!...Have a cup of coffee..then read this
pdf http://www.xfront.com/HideVersusExpose.pdf line by line,everything is there.Its also good to validate ur own examples with xsv or schematron or xmlspy or sun msv or ibm sqlc.
Regards
Balaji
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
jayadev Pulaparty Wrote:
Is there any other way i can refer to the someotherElement without qualifying it with some:??

Other simple way is to set elementformdefault to unqualified.This helps to avoid qualifying local elements.
Jayadev Pulaparty
Ranch Hand

Joined: Mar 25, 2002
Posts: 662
Can someone please reply to my earlier post addressing "what is the relevance of the elementFormDefault." in this thread??
Thanks.
Jayadev Pulaparty
Ranch Hand

Joined: Mar 25, 2002
Posts: 662
Does this mean that the elementFormDefault means to talk about whether or not to qualify the local elements explicitly with the namespace prefix??
Suppose that i have a schema (aaa.xsd) defining elements "BBB" and "CCC" in a namespace "ddd" with the elementFormDefault="qualified"
Now when i use element BBB as follows -
<BBB xmlns="ddd">
<CCC/> <!-- is this illegal ??-->
</BBB>
Do you mean to say that i have to do something like this -
<BBB xmlns="ddd">
<!-- this is the local element ?? -->
<ddd:CCC/>
</BBB>
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Originally posted by jim yin:
unqualified attributes are in the null namespace, rather than the default namespace. Does "null namespace" means "no namespace"?
[ September 10, 2002: Message edited by: jim yin ]

Hi Jim,
May be this document will you help you to clarify http://www.zvon.org/xxl/XMLSchemaTutorial/Output/ser_attributeFormDefault
Regards
Balaji
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Message to Jaya..
Sorry
Got to catch my bus ,i will try to reply you soon.
Regards
Balaji
[ September 10, 2002: Message edited by: Balaji Loganathan ]
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1180
Balaji,
I was referring from this document http://www.xfront.com/HideVersusExpose.pdf
Now you can check against XML Bible.

Roger says in this article -
A binary switch attribute in the schema is used to control the hiding/exposure of namespaces: by setting elementFormDefault="unqualified" the namespaces will be hidden (localized) within the schema, and by setting elementFormDefault="qualified" the namespaces will be exposed in instance documents.


He is explaining the idea well using different terminology and it's absolutely the same as what the XML bible says -
The third attribute, elementFormDefault, has the value qualified. This means that the elements being described in this document are in fact in a namespace; specifically they're in the target namespace given previously by the targetNamespace attribute. This does not mean that the elements being modeled necessarily have prefixes, merely that they are in some namespace.

Cheers,
Dan
Jayadev Pulaparty
Ranch Hand

Joined: Mar 25, 2002
Posts: 662
Dan,
What does this exactly mean ??
"elementFormDefault="unqualified" the namespaces will be hidden (localized) within the schema, and by setting elementFormDefault="qualified" the namespaces will be exposed in instance documents. "
Does this mean that with the elementFormDefault="unqualified", the targetnamespace becomes irrelevant?? If so, if i'm to use the elements in this schema i should use the noNameSpaceSchemaLocation stuff??
Please provide me with the missing links in my understanding and if possible, with a little example.
Thanks.
Jayadev Pulaparty
Ranch Hand

Joined: Mar 25, 2002
Posts: 662
Dan,
i'm reading the hideVsExpose.pdf and will get back with any doubts after done with it.
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Originally posted by Dan Drillich:
Balaji,

Cheers,
Dan

Hi Dan,
I'm not refering to statement abt elementformdefault,please see my FIRST reply to you,i'm refering to XML bible statement on attributeformdefault.
Regards
Balaji
Hi Jayadev,
elementformdefault "unqualified" doesn't mean that targetnamespace is irrelevant.
Please give a full reading on that pdf file,u will get a clear picture.I hope u also have the tutorial of roger(250 slides)power point.
Regards
Balaji
Rakesh Gudur
Ranch Hand

Joined: Apr 29, 2002
Posts: 79
Guys,
there seems a lot of hard talk going on.
Please refer to w3c Schema primer at
http://www.w3.org/TR/xmlschema-0/#UnqualLocals
I think this will clear the confusions.
Reg,
Rakesh.
--------------------
IBM Certified XML Dev.
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1180
Roger built a hierarchy of schemas that looks like -

The camera element in Camera.xsd is built from types in the three specific cameras.
By specifying elementFormDefault="unqualified" in the three specific cameras the elements within the camera element are not in any namespace. Roger calls this behavior - hiding.
I'm not sure I agree with this term, since there is nothing to hide - the elements in the three specific cameras in this design are _not_ in any namespace. So, what are we hiding?
This design doesn't scale because it doesn't allow these three cameras to share an element name and that's a major idea behind namespaces.
Cheers,
Dan
Jayadev Pulaparty
Ranch Hand

Joined: Mar 25, 2002
Posts: 662
Dan,
You mentioned two points here -
1)
I'm not sure I agree with this term, since there is nothing to hide - the elements in the three specific cameras in this design are _not_ in any namespace. So, what are we hiding?
2)
This design doesn't scale because it doesn't allow these three cameras to share an element name and that's a major idea behind namespaces.
==================
1) I don't agree with you on the first point. Even when said to be unqualified in the camera schema, if you look at the hideVersusExpose.pdf document, the root element of the instance document says as follows -
<my:camera xmlns:my="http://www.camera.org"......
All the body, lens and manual_adapter elements of the camera schema are fully aware of the namespaces of their types (since we are claiming these to be the body of my:camera element and the namespace "my" knows how to look at its own content definition). This means that only the namespace stuff are hidden from the xml instance document in this way, but the contents of the camera schema elements still respect the rules laid out in their own respective schemas;
Hence i feel that -
"the elements in the three specific cameras in this design are _not_ in any namespace" is wrong
I think the best way to check this out is by trying to stuff in contents of these elements different from their respective schemas and see how the schema validator reacts to this.
2) I agree with you on your second point; i think that is why he shows how to mix up the qualified and unqualified stuff to overcome this problem in the pdf document
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1180
Jayadev,
It's very interesting.
Here is the code -

My understanding is that only camera ended up in a namespace.
If we look at the following simpler example, you can see that in this case _all_ the elements are in the namespace http://www.camera.org.

In any case, I don't understand how the camera element in Camera1.xsd is in a namespace while the elementFormDefault is "unqualified".
Go figure,
Dan
(edited by Cindy to wrap one line of code so that everyone does not have to scroll)
[ September 12, 2002: Message edited by: Cindy Glass ]
Jayadev Pulaparty
Ranch Hand

Joined: Mar 25, 2002
Posts: 662
Dan,
The following is how i understand this whole story -
1)
"In any case, I don't understand how the camera element in Camera1.xsd is in a namespace while the elementFormDefault is 'unqualified' "
My understanding -
I definitely feel that the camera element and its contents (body, lens, adapter_type) are guided by the namespace "http://www.camera.org" and the internal contents by their respective schemas. This is why -
<my:camera xmlns:my="http://www.camera.org" xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xsi:schemaLocation="http://www.camera.org Camera1.xsd">
If you observe the above stuff, our my:camera element should follow the rules mentioned in Camera1.xsd. I guess there is no disagreement here.
Now Camera1.xsd has the elementFormDefault="unqualified". This means that all the xml instance documents governed by this schema "need not namespace qualify" its elements. Then you may say why "my:camera" and not simply "camera" in the instance document. Then we cannot enforce our schema of Camera1.xsd at all on the instance document. I think the whole idea here is to hide the namespace complexities of the xml elements in the instance documents, but not at all to relieve the elements totally from the schema dictated boundaries.
2)
"My understanding is that only camera ended up in a namespace "
I think the simple way for you to verify whether this statement is correct or not is to try changing the complexType definitions in one of the individual schemas and try to make the elements in the instance documents violate them and see what the schema validator says.
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Hi Dan!..
I guess u need to read again the link given by Rakesh http://www.w3.org/TR/xmlschema-0/#UnqualLocals and the Roger slides/pdf, and the most importantly the Powerpoint based tutorial of XML Schema by Roger, I mean the slides 9 and slides 15 of xml-schemas2.ppt ,this will make you to think more and get clear picture
I wish you have this files in your system if not u can get it from http://www.xfront.com/xml-schema.html
If you are still not happy,come up with more question please.
If you would like to try some validation by doing some violation on the instance document,better use XSV or Sun MSV,this will give more precise errors defn than others.
Regards
Balaji
Originally posted by Dan Drillich:
[/QB]
Jayadev Pulaparty
Ranch Hand

Joined: Mar 25, 2002
Posts: 662
Dan,
I've tested the stuff with the elementFormDefault="unqualified" for all the schemas against the Camera.xml document (in the HideVsExpose.pdf example) against the xsv schema validator successfully.
Then i added a new element
<xsd:element name="jaya" type="xsd:string"/>
to the Pentax.xsd schema and immediately the schema validator yelled saying that it expected the content <jaya/> in the manual_adapter type. This clearly shows the fact that "unqualified" is just a comfort creature sort of thing for the instance documents and the respective schemas defined for the namespaces are very much respected.
One more thing is that you were saying that with the elementFormDefault being set to unqualified, we will not be able to use the same element name in all the schemas. I don't think this is correct. The system always require you to namespace qualify the global elements and the local ones are tied to the globals. This should made the re-use possible.
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Originally posted by jim yin:
unqualified attributes are in the null namespace, rather than the default namespace. Does "null namespace" means "no namespace"?
[ September 10, 2002: Message edited by: jim yin ]

hi jim,
where did u got this lines,i'm afraid its not correct.want to check.
regards
balaji
Jayadev Pulaparty
Ranch Hand

Joined: Mar 25, 2002
Posts: 662
I guess the attributeFormDefault goes on similar lines to the elementFormDefault
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Originally posted by Jayadev Pulaparty:
I guess the attributeFormDefault goes on similar lines to the elementFormDefault

Thats Correct.
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1180
camera is a brand new element and it'll be placed in the targetNamespace ("http://www.camera.org"). Body, lens and adapter_type are inherited elements from different namespaces and since elementFormDefault is "unqualified" they 'lose' their original namespace and are no longer in any namespace.
Cheers,
Dan
jim yin
Ranch Hand

Joined: Aug 15, 2002
Posts: 111
Originally posted by Balaji Loganathan:

hi jim,
where did u got this lines,i'm afraid its not correct.want to check.
regards
balaji

Hi, Balaji:
The above is from "Professional XML Schemas". I still don't understand the concepts. The following are about elementFormDefault and attributeFormDefault:

...the default value for both is unqualified, which is why only globally declared elements and attributes need to be qualified in instance documents.

Please read p201-203. The explanation is not very clear.
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1180
Guys,
It's even more complex.
I changed elementFormDefault to "qualified" in camera.xsd.
My correct xml instance (according to XML Spy) is -
<?xml version="1.0"?>
<my:camera xmlns:my="http://www.camera.org"
xmlns:nikon="http://www.nikon.com"
xmlns entax="http://www.pentax.com"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" xsi:schemaLocation="http://www.camera.org Camera.xsd">
<my:body>
<nikon escription>Ergonomically designed casing for easy handling</nikon escription>
</my:body>
<my:manual_adapter>
<pentax:speed>1/10,000 sec to 100 sec</pentax:speed>
</my:manual_adapter>
</my:camera>

Now body and manual_adapter are in the targetNamespace while nikon escription and pentax:speed retain their original namespace.
Fascinating!
Dan
Jayadev Pulaparty
Ranch Hand

Joined: Mar 25, 2002
Posts: 662
Dan,
"camera is a brand new element and it'll be placed in the targetNamespace ("http://www.camera.org"). Body, lens and adapter_type are inherited elements from different namespaces and since elementFormDefault is "unqualified" they 'lose' their original namespace and are no longer in any namespace."
If they lose their original namespace (and hence no more guided by their respective schema), why is the schema validator complaining when i add an extra element <jaya/> (as i mentioned in a earlier posting today on this thread) to one of the individual schemas??
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Originally posted by jim yin:
Please read p201-203. The explanation is not very clear.

Hi Jim,
Its very clear there than in Roger slides.
The thumb rule is
1.Global elements and attributes should always be namespace qualified
2.Local attributes and element qualifiers can be hided or exposed by switching "unqualified"/"qualified" values for attributeformdefault,elementformdefault form
Its true that unqualified [b]GLOBAL[b] attributes will be in null namespace,rather than default namespace,unfortunately the book missed the word GLOBAL while explaining that concept.
If you don't mind,keep the above two lines in mind and read again the pages from 201-205.
If you are still confused,you can always post here.
Regards
Balaji
Jayadev Pulaparty
Ranch Hand

Joined: Mar 25, 2002
Posts: 662
Balaji,
I tried to see if i can extractthe namespace information even for the unqualified schema elements using xslt's name() function (which is supposed to give me the fully qualified name). To my surprise, this is just returning the local name. I'm perfectly convinced that these elements are in their respective namespaces and guided by relevant schemas.
My question is,
Why is the namespace information not extracted using xslt?
My xslt processor is Apache's xalan.
Please clarify.
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Originally posted by Dan Drillich:
Guys,
It's even more complex.
I changed elementFormDefault to "qualified" in camera.xsd.
My correct xml instance (according to XML Spy) is -
Now body and manual_adapter are in the targetNamespace while nikon escription and pentax:speed retain their original namespace.
Fascinating!
Dan

I can't get ur question fully?
When elementFormdefault qualified,the body and manual_adapter are in the namespace http://www.camera.org with "my" as qualifier.
jim yin
Ranch Hand

Joined: Aug 15, 2002
Posts: 111

Local attributes and element qualifiers can be hided or exposed by switching "unqualified"/"qualified" values for attributeformdefault,elementformdefault form

Thanks for good explanation. Here is what I understand:
By assigning "unqualified" value to attributeFormDefault or not, we always need to qualify the global attributes.
For local attributes, we can use "unqalified" value to turn off the namespace reference, and "qualified" to turn it on.
Is this right?
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Originally posted by Jayadev Pulaparty:
Balaji,
My question is,
Why is the namespace information not extracted using xslt?
My xslt processor is Apache's xalan.
Please clarify.

Your Stylesheet or ur XSLT program doesn't know anything about ur schema or DTD,it will just parse the XML.
Even if you add <java/> to ur schema instance and parse it using XSLT,it will.
Regards
Balaji
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Originally posted by jim yin:

For local attributes, we can use "unqalified" value to turn off the namespace reference, and "qualified" to turn it on.
Is this right?

Absolutely.The same will apply to element as well.
Hmm.. u got it mate.
Of course we are re-pharsing this right from first message
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to use elementFormDefault and attributeFormDefault?