The moose likes Product and Other Certifications and the fly likes complexType can be root element? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Product and Other Certifications
Reply Bookmark "complexType can be root element?" Watch "complexType can be root element?" New topic
Author

complexType can be root element?

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Suppose I want to use NAME elements inside PersonType elements in my Schema but I don't want to allow it to be the root element of my XML document. Also I want the freedom to use it differently in the future, e.g. NAME element inside a BookType element. Which of the following is the correct way of achieving it?
(I) <xsd:complexType name="NameType">
<xsd:sequence>
<xsd:element name="GIVEN" type="xsd:string"/>
<xsd:element name="FAMILY" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="PersonType">
<xsd:sequence>
<xsd:element name="NAME" type="NameType"/>
</xsd:sequence>
</xsd:complexType>
(II) <xsd:complexType name="PersonType">
<xsd:sequence>
<xsd:element name="NAME">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="GIVEN" type="xsd:string"/>
<xsd:element name="FAMILY" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>

Only (I) is correct
Only (II) is correct
Both (I) and (II) are correct

XML@Whiz answer is: B is correct. By defining the name element inside the xsd:element element which itself is a child of xsd:complexType element we have prevented it from being used elsewhere other than the PersonType element. Thus it cannot be the root element. Also we can define another name element inside a BookType element and make it mean whatever we want. The two name elements thus defined have nothing to do with each other. A is incorrect as (I) allows the NameType element to be used as the root element.
Neither (I) nor (II) is correct

I wouldn't agree: a complexType can't be the root element - it just defines a type of data, not an element...
What's your opinion?
Regards
Berny
 
 
subject: complexType can be root element?
 
Threads others viewed
minOccurs, maxOccurs
Web Service message level Encryption Decryption through public and private key
targetNamespace,xmlns
Top_Level Definition
Problem with SOAP
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture