Namespace question

A

Axel Dahmen

Hi,

I've got a question on namespaces. After reading
http://www.w3.org/TR/xml-names11 I still don't understand how namespaces are
applied to attributes - particularly in regard to how processing
applications are supposed to determine the proper validation DTD.

In the following XML:
-------------
<?xml version="1.0" ?>
<root xmlns="http://www.w3.org/TR/REC-html40"
xmlns:html="http://www.w3.org/TR/REC-html40">
<a href="page1.html" html:href="page2.html">
<html:a href="page1.html" html:href="page2.html">
</root>
-------------

How is an application supposed to interpret these attributes?

TIA,
Axel Dahmen
 
R

Richard Tobin

Axel Dahmen said:
<root xmlns="http://www.w3.org/TR/REC-html40"
xmlns:html="http://www.w3.org/TR/REC-html40">
<a href="page1.html" html:href="page2.html">
<html:a href="page1.html" html:href="page2.html">
</root>

How is an application supposed to interpret these attributes?

The <a> and <html:a> elements are both in the http://www.w3.org/TR/REC-html40
namespace. The href attributes are in no namespace, and the html:href
attributes are in the http://www.w3.org/TR/REC-html40 namespace.

The interpretation of attributes in no namespace depends on the element
they're on, so the interpretation of the href attributes is given by
the HTML spec.
After reading
http://www.w3.org/TR/xml-names11 I still don't understand how namespaces are
applied to attributes - particularly in regard to how processing
applications are supposed to determine the proper validation DTD.

Namespaces have nothing to do with determining the DTD. On the other
hand, namespaces *are* used to choose an XML Schema for validation.

The schema definition of the html:href attribute (if such a thing
exists) should appear in the HTML schema, because it's in the HTML
namespace. The definition of the href attribute should also appear
there, because it's on an element in the HTML namespace.

-- Richard
 
J

Johannes Koch

Richard said:
The schema definition of the html:href attribute (if such a thing
exists) should appear in the HTML schema, because it's in the HTML
namespace. The definition of the href attribute should also appear
there, because it's on an element in the HTML namespace.

And, of course, the HTML 4 specification does not define or use a
namespace, because HTML is no XML application.
 
R

Richard Tobin

And, of course, the HTML 4 specification does not define or use a
namespace, because HTML is no XML application.

I was talking theoretically :)

-- Richard
 
J

Joe Kesselman

This looks awfully like a homework problem. If so, shame on you. But
it's a common point of confusion, so it's worth explaining in detail
whether or no.

Attributes are bound to a namespace *only* if their names use a prefix.
Unlike elements, they are not affected by an inherited default
attribute, nor do they pick up the namespace of their element.
<?xml version="1.0" ?>
<root xmlns="http://www.w3.org/TR/REC-html40"
xmlns:html="http://www.w3.org/TR/REC-html40">

These two attributes, of course, default the default namespace and the
html: prefix respectively. Since the default is defined, the <root>
element itself is in the namespace http://www.w3.org/TR/REC-html40 ...
which may not be what was intended.
<a href="page1.html" html:href="page2.html">

Since the default namespace is set, the <a> element is in that
namespace. Since html:href has a prefix, it is in the namespace bound to
that prefix (which also happens to be http://www.w3.org/TR/REC-html40).
Since href does not have a prefix, is is *NOT* in that namespace -- it's
in the "no namespace" namespace. The fact that the element is namespaced
has no effect on the attributes.
<html:a href="page1.html" html:href="page2.html">

html: is bound, so html:a is an a element in that namespace.
The attributes are as discussed before; the fact that the element is
namespaced has no effect on the attributes..
 
A

Axel Dahmen

Thanks, Richard, I'm still trying to understand XML, so your information is quite appreciated!
Namespaces have nothing to do with determining the DTD. On the other
hand, namespaces *are* used to choose an XML Schema for validation.

I don't understand... Let's keep XML Schema out of focus for a minute.. From the XML Spec., DTDs are used by XML parsers to validate an XML document. So, DTDs are to XML what header files are to C++, aren't they?

For an XML parser being able to validate an XML document it uses DTDs. If I want to create an XML document being compiled from several DTDs (e.g. XHTML1.0), I add a reference to the corresponding DTDs to my XML document. For an XML parser being able to determine the correct DTD from a given set of DTDs at the beginning of an XML document, namespaces are used then. Aren't they?
 
A

Axel Dahmen

Thanks a lot, Joe. Like I said in my previous post, I'm currently learning XML and your information is QUITE appreciated!
This looks awfully like a homework problem. If so, shame on you. But
it's a common point of confusion, so it's worth explaining in detail
whether or no.

No no, I'm just learning for myself... Look at me.. would I EVER cheat? ;-)
In my other life I'm a software engineer, but admittedly this XML specification is too hard for me to grasp.


I understand how attributes are saved and stored in a tree considering namespaces. What I don't understand is how an application is supposed to determine a valid attribute to apply to an element:

Imagine there's an application being able to render XML/XSL and XHTML1.0. Let's call it XaPP...

From what I understand, DTDs are to XML what header (.h) files are to C++, so in a document to render both, some proprietary XML and some embedded XHTML, I'd add 2 DTDs:

<?xml version="1.1"?>
<!DOCTYPE greeting SYSTEM "hello.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://...dtd">

Next, I'd assign a namespace to the XHTML DTD: (To stress my point, I'll add the default namespace to XHTML as well)

<body xmlns="http://www.w3.org/TR/REC-html40"
xmlns:html="http://www.w3.org/TR/REC-html40">

Then I'd add nodes to the tree:

...
<a href="page1.html" html:href="page2.html">
<html:a href="page1.html" html:href="page2.html">
</body>


Three questions arise:

a) Which element declaration do I have to add to "hello.dtd" to allow for foreign (XHTML) elements to appear in the XML tree?

b) When the XaPP application reaches the <a> (or <html:a>) element, which href / html:href attribute will it use to render the hyperlink?

c) Shouldn't at least two of the href / html:href attributes be interpreted as invalid by the parser as they are not mentioned in the appropriate DTD?


Thanks a lot for helping me to understand!! (Which I unfortunately don't yet..)

Regards,
Axel Dahmen
These two attributes, of course, default the default namespace and the
html: prefix respectively. Since the default is defined, the <root>
element itself is in the namespace http://www.w3.org/TR/REC-html40 ...
which may not be what was intended.

Oops, my fault... ;)
 
J

Johannes Koch

Axel said:
For an XML parser being able to validate an XML document it uses DTDs.

Only one DTD per document.
If I want to create an XML document being compiled from several DTDs (e.g. XHTML1.0),
compiled?

I add a reference to the corresponding DTDs to my XML document. For an XML parser being able to determine the correct DTD from a given set of DTDs at the beginning of an XML document,

There is no set of DTDs at the beginning of an XML document. There is
only _one_ document type declaration which references _one_ document
type definition.
namespaces are used then. Aren't they?

No.

DTDs don't know namepaces. They are older than XML namespaces. For a DTD
an element foo:bar is not an element named bar from a namespace with the
prefix foo, but an element named foo:bar.
 
J

Joe Kesselman

Axel said:
What I don't understand is how an application is supposed to determine a valid attribute to apply to an element:

Remember, the attributes have specific meanings to applications.
Therefore, they're generally hardcoded into the application.\
So the decision's made by the programmer.
From what I understand, DTDs are to XML what header (.h) files are to C++
> so in a document to render both, some proprietary XML and some
embedded XHTML, I'd add 2 DTDs:

No. As others have said, one DTD per document, made up of an External
Subset and an Internal Subset. If you want to intermix other structures,
you either need a DTD which leaves some areas unvalidated (using ANY),
or you need to move to schemas. Note that XHTML *IS* intended to be
primarily schema-based rather than DTD-based.

Next, I'd assign a namespace to the XHTML DTD

No. Again as others have said: DTDs don't do namespaces. In fact, DTDs
are pretty darned nearly INCOMPATABLE with namespaces. If you're working
with namespaced documents, do not waste time studying DTDs; go directly
to schemas, or drop back to well-formed rather than validated.
 
A

Axel Dahmen

compiled?

^= combined


Thanks to all of you for your valuable help.

Regards,
Axel Dahmen
 
A

Axel Dahmen

I see, from all responses I now see that dealing with DTD on XML seems to be a waste of time then. So I'll forward to Schema now.

The XML specification is older than XML Schema. So is it safe then to assume that an XML document having no DTD but a reference to XML Schema is still declared to be valid (provided the XML data is valid)?

Thanks to all of you for your valuable help.

Regards,
Axel Dahmen
 
J

Joe Kesselman

Axel said:
I see, from all responses I now see that dealing with DTD on XML seems to be a waste of time then.

There are folks who will argue about this, but that's essentially the
conclusion I've reached. DTDs were inherited from SGML, back when XML
was new and XML was mostly being processed through tools also inherited
from SGML. While it *might* have been possible to extend DTDs to deal
with namespaces, it would have been somewhat ugly and the namespace
committee fairly explicitly decided that it was better to leave them
behind.

If we had it all to do over again, it might have been better to have
defined the XML Infoset first -- including namespaces and some of the
other features -- and then derived schemas and the XML syntax and the
other tools and APIs from that basis. But doing it in this order, while
it has resulted in some confusion, allowed XML to get out into the real
world and establish itself a lot faster, so I can't really argue that it
was the wrong decision.
So is it safe then to assume that an XML document having no DTD but a
> reference to XML Schema is still declared to be valid (provided the
> XML data is valid)?

Due to the order in which things were defined, there are actually two
separate definitions of validity -- validity against the DTD (if any)
and validity against the schema (if any). Schema wasn't allowed to alter
the basic XML specification, so it wasn't allowed to change or enhance
the old meaning of validity; it had to add a secondary one. (There are
also some subtleties in exactly where additional information from the
schema winds up in the XML Infoset that also come from this decision
that schemas add information rather than changing information, which you
may be able to ignore for a while.)

So: There is Validity, and there is Schema Validity. Normally you're
only worried about one, and tools may mask this distinction by reporting
invalid if either stage fails.

I know, more detail than you wanted. And if you're lucky, more
information than you'll need for a while. But you asked.
 
J

Joe Kesselman

I should add that, colloquially, "invalid" these days is often used to
mean "not valid against whichever schema language we're checking this
kind of document against."
 
A

Axel Dahmen

I know, more detail than you wanted. And if you're lucky, more
information than you'll need for a while. But you asked.

No no, not at all!! You've been a great, great exhaustive source for me to finally understand namespaces and DTDs (along with Johannes, of course!). Your comments have laid out a good path for me to further dig into XML and finally write my own applications consuming XML.

The Namespace and XML specifications don't yield this kind of information, even XML 1.1 doesn't decouple from DTDs.

So, finally, from what you've wrote, an application is going to examine an element's attributes and interpreting them in a way whichever it thinks is appropriate, right? I assume namespaces in attributes are only used to introduce foreign attributes with probably predefined external meaning then.

Best wishes,
www.dashop.de
Axel Dahmen
 

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,158
Latest member
Vinay_Kumar Nevatia
Top