Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
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.
  #2 (permalink)  
Old September 29th, 2010, 11:50 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
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/
  #3 (permalink)  
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.
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 04:02 AM
Any tool to validate the length of each xml attribute against an xml schema LeoMathew XSLT 0 December 7th, 2009 01: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



All times are GMT -4. The time now is 09:33 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.