Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Namespaces on Schemas

Reply
Thread Tools

Namespaces on Schemas

 
 
inerte@gmail.com
Guest
Posts: n/a
 
      10-13-2005
Hello all!

I need to build an XML file structure so a client can import data to
one of our systems. Totally new to XML, I learned about Namespaces and
DTD, and built a nice spec using them. Now I am trying to use XML
Schemas to tell more about what kind of data are allowed on each
element/attribute, but I can't understand how to mix Namespaces and
Schemas.

Can anyone give me tips, starting points, about how to specify the
Schema for the following example XML?

<library xmlns:book="book" xmlns:author="author">
<book:book>
<book:title>Example</book:title>
<bookages>150</bookages>
</book:book>
<author:author>
<author:title>Mr</author:title>
<author:name>Julio Nobrega</author:name>
</author:author>
</library>

I want to say that the <title> tag has different validation rules
depending on the namespace...

Thank you!

--
Julio Nobrega
http://www.inerciasensorial.com.br

 
Reply With Quote
 
 
 
 
Chris
Guest
Posts: n/a
 
      10-13-2005
You are mis-using namespaces. Namespaces should only really be used
when you are addressing xml from different sources, say, from two
different departments, and want to keep their definitions distinct. As
someone who is producing an entire xml document, one should never use
more than one namespace. When you are aggregating documents from
different sources and are concerned about namespace clashed, you then
think about using a set of namespaces.

Here are my rules for the use of namespaces:
Rule 1 of namespace: Don't
Rule 2 of namespaces: Not yet
Rule 3 of namespaces: only when you need to

Thus your xml would look like:

<library>
<book>
<title>here</title>
<author>there</author>
</book>
<author>
<title>here</title>
<name>there</name>
</author>
</library>

xml Schema is nice because it allows you to define structure that may
be called the same, but is used in different places. e.g.:

You wanted the library/book/title element to have an ISBN attribute,
but the library/book/title element to have a number attribute (i.e.
this is the author's Nth book). Any good schema reference will tell
you how to define children element of the same name but of different
(complex/simple) types.

In conclusion, that the title element is a child of the book element
implies that it is a "book title", there's no need to define different
namespaces.

take a look at http://builder.com.com/5100-6389-1046618.html for more
on namespaces.

 
Reply With Quote
 
 
 
 
Richard Tobin
Guest
Posts: n/a
 
      10-13-2005
In article <(E-Mail Removed) .com>,
<(E-Mail Removed)> wrote:

><library xmlns:book="book" xmlns:author="author">


Namespace names are supposed to be absolute URLs.

-- Richard
 
Reply With Quote
 
Jason Karns
Guest
Posts: n/a
 
      10-13-2005
Actually, namespaces are designated as URI's not URL's. Taken from the W3C's recommendation on XML namepsaces: <http://www.w3.org/TR/REC-xml-names/#ns-decl>

[Definition:] The attribute's value, a URI reference, is the namespace name identifying the namespace. The namespace name, to serve its intended purpose, should have the characteristics of uniqueness and persistence. It is not a goal that it be directly usable for retrieval of a schema (if any exists). An example of a syntax that is designed with these goals in mind is that for Uniform Resource Names [RFC2141]. However, it should be noted that ordinary URLs can be managed in such a way as to achieve these same goals.

In other words, the namespace URI has to be unique and that's it. URL's, by definition, are unique (all URL's are URI's but not vice versa) therefore, acceptable as namespace names. Generally, one simply uses a URL for the namespace name, however, this URL doesn't need to point to any actual document. Convention and general usefullness suggests placing the schema or DTD of said namespace at said URL is a good idea, and I concur.

nntp://news.cis.ohio-state.edu/comp.text.xml/<dimi0t$2v4l$(E-Mail Removed)>

In article <(E-Mail Removed) .com>,
<(E-Mail Removed)> wrote:

><library xmlns:book="book" xmlns:author="author">


Namespace names are supposed to be absolute URLs.

-- Richard

[comp.text.xml]
 
Reply With Quote
 
Richard Tobin
Guest
Posts: n/a
 
      10-13-2005
In article <dimlva$suq$(E-Mail Removed)-state.edu>,
Jason Karns <karns.17@n!o!s!p!a!m.osu.edu> wrote:

>Actually, namespaces are designated as URI's not URL's.


I know that. I was trying not to obscure the point with subtleties.

-- Richard
 
Reply With Quote
 
Henry S. Thompson
Guest
Posts: n/a
 
      10-14-2005
The W3C XML Schema Primer [1] has a very good introduction to this
topic which I think you will find helpful.

ht

[1] http://www.w3.org/TR/xmlschema-0/
--
Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
Half-time member of W3C Team
2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
Fax: (44) 131 650-4587, e-mail: http://www.velocityreviews.com/forums/(E-Mail Removed)
URL: http://www.ltg.ed.ac.uk/~ht/
[mail really from me _always_ has this .sig -- mail without it is forged spam]
 
Reply With Quote
 
inerte@gmail.com
Guest
Posts: n/a
 
      10-20-2005
Chris wrote:
> You are mis-using namespaces. Namespaces should only really be used
> when you are addressing xml from different sources, say, from two
> different departments, and want to keep their definitions distinct.


Thank you Chris. I solved the problem by not using namespaces on my
own created file

Actually, I gave up on XML Schema and started using RELAX NG, but
that's another topic... not that I know how to use namespaces on RELAX
NG either, but following your advice I am not even looking how to do
it, for now

 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Schemas & Namespaces chuck XML 1 12-30-2007 02:05 PM
Microsoft CDO Schemas... Green Start Button ASP .Net 1 08-11-2005 09:16 PM
Strange problem with JDOM, Xerces and XML Schemas Soeren Java 2 09-22-2004 10:17 AM
mutliple schemas/namespaces - xml validation Dominique XML 3 06-29-2004 06:29 PM
dynamic color schemas with ASP.NET Oleg Ogurok ASP .Net 1 06-08-2004 01:06 PM



Advertisments