XML Document Using XML Schema?{rep points included!}
This seems very confusing to me so i am hoping that someone might be able to clarify. :)
Im reading an old book (June 2000) on XML so i don't know if this is still the way to do things. The book shows the following lines. I understand that the first line is a PI instruction to the XML parser. Now the second is the xml schema instance. Third is the xml doc namespace and the forth is the location of the xml schema doc .xsd. Now why is it needed that a namespace be defined for the schema? I understand namespaces as they relate to xml elements but is it the same for the schema,
to avoid collisions? Thanks.
Code:
<?xml version="1.0"?>
<addressBook xmlns:xsi="http://www.w3.org/1999/XMLSchema/instance"
xmlns="http://www.oreilly.com/catalog/javaxml"
xsi:schemaLocation="http://www.oreilly.com/catalog/javaxml
mySchema.xsd">
Re: XML Document Using XML Schema?{rep points included!}
Pretty much.... in this case, one could have multiple addressBook schemas based on application.... Outlook, ThunderBird, Netscape, myOwn, etc....
Each one would have it's own slightly different format.... but they are all addressBook. By putting a namespace on the schema, it differentiates between just which schema should be used.
Tg
Re: XML Document Using XML Schema?{rep points included!}
Thanks TG. One more thing. If the line below specifies the namespace and schema to use then what is the second line ((located @ my previous post) the one that declares the schema instance) used for? The line below seems to cover the location and .xsd file to use.
Code:
xsi:schemaLocation="http://www.oreilly.com/catalog/javaxml
mySchema.xsd">
Re: XML Document Using XML Schema?{rep points included!}
Quote:
Originally Posted by Dilenger4
Im reading an old book (June 2000) on XML so i don't know if this is still the way to do things. The book shows the following lines. I understand that the first line is a PI instruction to the XML parser.
Actually, no. Although the xml declaration has the same syntax as a generic processing instruction, according to the standard it isn't, and thus, for example, never shows up as a processing instruction node in the DOM tree, or is reported as a processing instruction event by SAX parsers.
Quote:
Now the second is the xml schema namespace.
More precisely, it's the XML schema instance namespace that contains schemaLocation and a few other attributes. The schema namespace, on the other hand, contains the schema element, the element element, etc.
Quote:
Third is the xml doc namespace and the forth is the location of the xml schema doc .xsd.
Correct.
Quote:
Now why is it needed that a namespace be defined for the schema?
Not sure what you mean.
The schema instance namespace is introduced because the schemaLocation element from there is used. The javaxml namespace is introduced to define a namespace for the document. The declaration could have been omitted; in that case, the element addressBook would have been in the default namespace. The namespace here is to differentiate the javaxml addressBook from the csharpxml addressBook and the pythonxml addressBook, etc.
The schemaLocation ties namespaces and schema files together. This attribute declares that for all elements from the javaxml namespace, use mySchema.xsd as the schema.
To tie a schema file to the default namespace, you'd use the noNamespaceSchemaLocation attribute.
Re: XML Document Using XML Schema?{rep points included!}
Thanks CB. The following clears things up.
Quote:
Posted by CornedBee
More precisely, it's the XML schema instance namespace that contains schemaLocation and a few other attributes.
So the xml schema namespace has nothing to do with a user definable .xsd, meaning it dosen't specify the location and or the .xsd itself.
I guess the xml schema namespace is almost like declaring a namespace in a jsp page so you can use the tags contained within.
Re: XML Document Using XML Schema?{rep points included!}
Correct. In fact, it's exactly like that, except that one uses the xmlns:* pseudo-attributes, while the other uses custom JSP instructions or tags from the jsp namespace.
Re: XML Document Using XML Schema?{rep points included!}
Fantasitc! Thanks guys. CB i haven't forgot about the reps. I still owe you from previous stuff. ;)