Jump to content

Questions about XML schemas


Guest JimmyJimmy

Recommended Posts

Guest JimmyJimmy

I'm trying to fully understand XML schemas and the XML documents that reference those schemas. I've worked through some online XML tutorials, but there are still some things I'm unsure about. At the end of this post, I've copied in an XML schema and XML document from a book I'm reading. Questions about the XML schema1. In the 'xsd:schema' element, the 'xmlns' attribute has setup a default namespace. Was this necessary? Is this default namespace actually being (implicitly) used anywhere within the schema document?2. In the 'xsd:schema' element, is it necessary to specify the 'targetNamespace' attribute? Does this attribute actually specify anything meaningful? Is it the link between a document and a schema?3. In the 'xsd:schema' element, I understand that the 'xmlns:xsd' attribute maps the namespace shortcut 'xsd' to a namespace URI, but what schema/DTD/document specifies the elements and attributes (such as <element>, etc) that are legal within a schema file? Or is this just an implicit part of the XML schema framework?4. In the 'xsd:schema' element, if the 'elementFormDefault' attribute was not set to "qualified", what would the practical effect be?5. In the first 'xsd:element' element, why isn't the 'name' attribute specified as 'xsd:name' - does this 'name' attribute belong to the xsd namespace, or does it belong to the default namespace?Questons about the XML document1. In the 'ContactInformation' element, it appears that the 'xsi:schemaLocation' attribute is responsible for mapping a namespace URI to an actual file location of a valid XML schema. Is this correct? Is it possible to specify a number of such mappings? If so, what is the syntax? Are the mappings all specified within a single attribute, or is each specified in an individual attribute?2. Why isn't the 'xsi' namespace mapped to an XML schema document? How does the parser know what constitutes valid content for the 'xsi:schemLocation' attribute? Or do all parsers implicitly know about this?

<?xml version="1.0" encoding="UTF-8"?><xsd:schema	xmlns:xsd="http://www.w3.org/2001/XMLSchema"	targetNamespace="http://simple.example.com/CInfoXmlDoc"	xmlns="http://simple.example.com/CInfoXmlDoc"	elementFormDefault="qualified">	<xsd:element name="ContactInformation">		<xsd:complexType>			<xsd:sequence>				<xsd:element name="Name" type="xsd:string" />				<xsd:element name="Address">					<xsd:complexType>						<xsd:sequence>							<xsd:element name="Street" type="xsd:string" />							<xsd:element name="City" type="xsd:string" />							<xsd:element name="State" type="xsd:string" />							<xsd:element name="Country" type="xsd:string" />						</xsd:sequence>					</xsd:complexType>				</xsd:element>				<xsd:element name="HomePhone" type="xsd:string" />				<xsd:element name="Email" type="xsd:string" />			</xsd:sequence>		</xsd:complexType>	</xsd:element></xsd:schema><?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?><ContactInformation	xmlns="http://simple.example.com/CInfoXmlDoc"	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"	xsi:schemaLocation="http://simple.example.com/CInfoXmlDoc file:./CInfoXmlDoc.xsd">	<Name>John Doe</Name>	<Address>		<Street>4140 Network Circle</Street>		<City>Santa Clara</City>		<State>California</State>		<Country>USA</Country>	</Address>	<HomePhone>123-456-7890</HomePhone>	<Email>abc@xyz.com</Email></ContactInformation>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...