*
The moose likes XML and Related Technologies and the fly likes Complex Type creation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Complex Type creation" Watch "Complex Type creation" New topic
Author

Complex Type creation

Sudhanshu Mishra
Ranch Hand

Joined: May 28, 2011
Posts: 217

Hi all,
I came across a paragraph as per the site
XML SCHEMA:

The elements and attributes declared within the xsd:complexType element are considered local to the complex type. Local elements and attributes can only be used within the context where they're defined. This raises an interesting question about whether local elements/attributes need to be namespace qualified in instance documents. Since local elements and attributes will always contain an ancestor element (typically a global element) qualified by the target namespace, one could argue that it's not necessary.

Now,what does it mean,that i do not have to use namespace prefixes for the child elements and attributes in the XML document?Do the global elements always have to be prefixed with their namespaces in the xml schema?

Please guide me through.
Thanks
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10240
    
168

I believe the article I pointed to you, in your other post http://www.coderanch.com/t/573881/XML/XML-schema#2612230 will help you understand this.

[My Blog] [JavaRanch Journal]
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 535
    
    3
...Since local elements and attributes will always contain an ancestor element (typically a global element) qualified by the target namespace, one could argue that it's not necessary.

That is from some article. "One could argue"... that implies one could argue otherwise as well. So it has to be put it in the context of the complete article. That "argue" should just be trying to help anchoring something to readers' mind to help understanding of an aspect of the design. I wouldn't though "argue" otherwise with them. That wouldn't help.

Now,what does it mean,that i do not have to use namespace prefixes for the child elements and attributes in the XML document?

Now this is your digestion. Of course, it does not mean that. Besides, prefix is only an artefact for the convenience of the author of an instance xml document. Child elements and attributes have all the provisions available in the w3 schema language to be in any namespace imaginable. (It can be prefixed or non-prefixed in case of element having a default namespace; but for attributes, in case they are not in null namespace, must be prefixed.) But it is not easy to digested in one go, so I suggest you should not be too dragged by the leg by those subtleties before understanding other more readily unstandable and needed things first.

Do the global elements always have to be prefixed with their namespaces in the xml schema?

If the target namespace in the xml schema describing those globals (or locals, for that matter, be mindful) is not null and that the author of the instance document happens to not using default namespace for it, sure, it has to be prefixed. In case they are in null namespace, they aren't prefixed.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Complex Type creation