XML Namspaces

  • Thread starter Chase Preuninger
  • Start date
C

Chase Preuninger

What did I do wrong?

<?xml version="1.0"?>
<rfs:filesystem xmlns:rfs="http://www.somewebpage.com/rfs"/>
<rfs:root>
<rfs:attr key="name" value="c:\"/>
<rfs:folder>
<rfs:attr key="name" value="Users"/>
<rfs:file>
<rfs:attr key="name" value="pic.jpg"/>
<rfs:attr key="size" value="5675675"/>
<rfs:attr key="lastmod" value="5359573579797693"/>
</rfs:file>
<rfs:folder>
<rfs:attr key="name" value="Chase"/>
<rfs:attr key="compressed" value="true"/>
<rfs:file>
<rfs:attr key="name" value="config.sys"/>
<rfs:attr key="size" value="5678"/>
<rfs:attr key="execute" value="false"/>
</rfs:file>
</rfs:folder>
</rfs:folder>
</rfs:root>
</rfs:filesystem>
 
J

Joseph J. Kesselman

Chase said:
I also don't get what the purpose of the xmlns is

Sounds like you need a basic education in what XML Namespaces are.
Reading a good modern XML tutorial might be worthwhile at this point. (I
usually point folks to the articles and tutorials at
http://www.ibm.com/xml, but I admit I'm biased.)

For info specifically about XML Namespaces, see James Clark's description at
http://www.jclark.com/xml/xmlns.htm
or the official (but somewhat harder to read) definition at
http://www.w3.org/TR/REC-xml-names/
 
C

Chase Preuninger

I have I big book on XML, I just never really got the entire thing
about the xmlns.
 
J

Joseph J. Kesselman

Chase said:
I have I big book on XML, I just never really got the entire thing
about the xmlns.

Namespaces are a way of managing XML-based grammars so they can be
reliably recognized by applications, and if necessary intermixed in a
single document. The xmlns attributes are used to bind prefixes (which
are just "syntactic sugar" shorthand) to the namespace names (strings
formatted as absolute URI references). Those bindings are scoped, so the
same prefix may mean different URIs in different parts of the program.
It's also possible to set up a default namespace for elements in one of
those parts, just to save a bit of typing. (This sometimes improves
readabilty, sometimes makes it worse.)

The namespace names are formatted as URI references because "we already
know how to manage those so they won't conflict with each other." And
that's all there is to that. The namespace name has no other built-in
meaning beyond being the name for this namespace. There is no guarantee
that there is anything meaningful behind that URI if you try to
dereference it, or what you might find there if anything is present.
Basically, you shouldn't be trying. (The Semantic Web folks said they
would come up with a standard for what a namespace URI might point to. I
haven't heard any concrete proposals, and it's been several years. Don't
hold your breath.)

So namespaces are just an alternative to having to always type a
<gawdaful_long_name_that_you_hope_nobody_else_used/>. That really is all
there is to them.


Most modern XML standards assume you're working with namespaced
documents. XML Schema, XPath, XSLT, the Semantic Web stuff, XHTML,
XQuery, and so on all assume namespaces are a prerequisite.

Read some tutorials and/or re-read that section of the book -- or find
another document which explains this better.
 
C

Chase Preuninger

Does the xmlns attribute need to have a URI or could it just contain
anything?
 
J

Joseph J. Kesselman

Chase said:
Does the xmlns attribute need to have a URI or could it just contain
anything?

A "namespace name" must conform to the syntax of an Absolute URI
Refrence -- an absolute URI possibly followed by a fragment identifier.

If you really mean the xmlns attribute (xmlns=, as opposed to
xmlns:foo=), that's the default namespace declaration. Same restriction
on its value.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top