Wrox Programmer Forums
|
BOOK: Beginning XML, 4th Ed ISBN: 978-0-470-11487-2
This is the forum to discuss the Wrox book Beginning XML, 4th Edition by David Hunter, Jeff Rafter, Joe Fawcett, Eric van der Vlist, Danny Ayers, Jon Duckett, Andrew Watt, Linda McKinnon; ISBN: 9780470114872
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning XML, 4th Ed ISBN: 978-0-470-11487-2 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 27th, 2010, 11:20 AM
Registered User
 
Join Date: Sep 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Question XML Schema Help

Hello everyone,
I am a newbee in XML, and have a problem in XML schema. First I am writing an example from "Beginning XML" from Wrox.

**---------------- name5.xsd ----------------**
Code:
<?xml version="1.0" ?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:target="http://www.example.com/name"
targetNameSpace="http://www.example.com/name" elementFormDefault="qualified">   /* ******* Problem 1 ******* */
	<element name="name">
		<complexType>
			<sequence>
				<element name="first" type="string" />	  /* ******* Problem 2 ******** */
				<element name="second" type="string" />
				<element name="third" type="string" />
			</sequence>
			<attribute name="title" type="string" />
		</complexType>
	</element>
</schema>

**---------------- name5.xml ----------------**
Code:
<?xml version="1.0" ?>
<name xmlns="http://www.example.com/name" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.example.com/name name5.xsd" title="Mr.">   /* ******* Problem 3 ******** */
	<first>John</first>
	<middle>Fotzgerald Johansen</middle>
	<last>Doe</last>
</name>
**--------------------------------------------------------------**

Problems:

Problem 1: Why is root element named - "schema", and not something else? And, if the URI in the namespace should be unique (I mean, they don't point to any URL or address; they are just unique name), why are we only using - xmlns="http://www.w3.org/2001/XMLSchema"?

Problem 2: type="string". The book says "string" is a datatype. Now type - "http://www.w3.org/2001/XMLSchema\third:string" is again only a unique name (it is not pointing to any URL); so where is the definition of primitive datatype. And if parser knows the definition, then why can't be it "target:string"

Problem 3: What is "xsi:schemaLocation". How does parser know, it can take namespace-location pair

Extra Problem: This one is hard to explain.
<complextype name="nameType">
....content model....
</complexType>
<element name="name" type="target:nameType" />

Now name="nameType" and ' type="target:nameType" ' belongs to different namespaces, then what does "target:nameType" point to ?


Thanks in advance.
 
Old September 29th, 2010, 11:50 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Quote:
Originally Posted by gushal View Post
Hello everyone,

Problems:

Problem 1: Why is root element named - "schema", and not something else? And, if the URI in the namespace should be unique (I mean, they don't point to any URL or address; they are just unique name), why are we only using - xmlns=http://www.w3.org/2001/XMLSchema?
Because the schema for schemas defines the root element as being named schema.

Problem 2: type="string". The book says "string" is a datatype. Now type - "http://www.w3.org/2001/XMLSchema\third:string" is again only a unique name (it is not pointing to any URL); so where is the definition of primitive datatype. And if parser knows the definition, then why can't be it "target:string"
Because the target namespace applies to the instance document, not the schema document. The primitive datatypes are defined in the schema for schemas document.

Problem 3: What is "xsi:schemaLocation". How does parser know, it can take namespace-location pair
Where the schema is located (not always used by the XML parser). It knows because it's defined that way in the schema's schema and so it's hardcoded into conformant parsers.

Extra Problem: This one is hard to explain.
<complextype name="nameType">
....content model....
</complexType>
<element name="name" type="target:nameType" />

Now name="nameType" and ' type="target:nameType" ' belongs to different namespaces, then what does "target:nameType" point to ?
Don't get this one.


Thanks in advance.
Hope this helps
__________________
Joe
http://joe.fawcett.name/
 
Old September 29th, 2010, 06:17 PM
Registered User
 
Join Date: Sep 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Smile Thanks


Thanks for explanation. It's quiet clear now.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Any tool to validate the length of each xml attribute against an xml schema LeoMathew XML 6 December 8th, 2009 05:02 AM
Any tool to validate the length of each xml attribute against an xml schema LeoMathew XSLT 0 December 7th, 2009 02:18 AM
Problem with date format in XML and XML Schema nelly78 XML 3 October 23rd, 2009 09:43 AM
create xml from xml schema in java zhebincong XML 1 October 6th, 2009 04:10 AM
XML, XML Schema, JavaScript, ASP cyberjames2003 XML 0 June 4th, 2003 04:49 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.