Connecting Tech Pros Worldwide Forums | Help | Site Map

Namespace question

Axel Dahmen
Guest
 
Posts: n/a
#1: Oct 11 '06
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



Richard Tobin
Guest
 
Posts: n/a
#2: Oct 11 '06

re: Namespace question


In article <egj2tv$rhj$1@online.de>,
Axel Dahmen <NO_SPAM@NoOneKnows.invalidwrote:
Quote:
><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 <aand <html:aelements 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.
Quote:
>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
Johannes Koch
Guest
 
Posts: n/a
#3: Oct 11 '06

re: Namespace question


Richard Tobin schrieb:
Quote:
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.
--
Johannes Koch
Spem in alium nunquam habui praeter in te, Deus Israel.
(Thomas Tallis, 40-part motet)
Richard Tobin
Guest
 
Posts: n/a
#4: Oct 11 '06

re: Namespace question


In article <452d6670$0$97229$892e7fe2@authen.yellow.readfreen ews.net>,
Johannes Koch <koch@w3development.dewrote:
Quote:
>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
Joe Kesselman
Guest
 
Posts: n/a
#5: Oct 11 '06

re: Namespace question


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.
Quote:
<?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.
Quote:
<a href="page1.html" html:href="page2.html">
Since the default namespace is set, the <aelement 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.
Quote:
<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..







--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Axel Dahmen
Guest
 
Posts: n/a
#6: Oct 14 '06

re: Namespace question


Thanks, Richard, I'm still trying to understand XML, so your information is quite appreciated!
Quote:
Quote:
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.
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?

Axel Dahmen
Guest
 
Posts: n/a
#7: Oct 14 '06

re: Namespace question


Thanks a lot, Joe. Like I said in my previous post, I'm currently learning XML and your information is QUITE appreciated!
Quote:
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
Quote:
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... ;)

Johannes Koch
Guest
 
Posts: n/a
#8: Oct 14 '06

re: Namespace question


Axel Dahmen schrieb:
Quote:
For an XML parser being able to validate an XML document it uses DTDs.
Only one DTD per document.
Quote:
If I want to create an XML document being compiled from several DTDs (e.g. XHTML1.0),
compiled?
Quote:
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.
Quote:
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.
--
Johannes Koch
Spem in alium nunquam habui praeter in te, Deus Israel.
(Thomas Tallis, 40-part motet)
Joe Kesselman
Guest
 
Posts: n/a
#9: Oct 14 '06

re: Namespace question


Axel Dahmen wrote:
Quote:
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.
Quote:
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.

Quote:
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.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Axel Dahmen
Guest
 
Posts: n/a
#10: Oct 14 '06

re: Namespace question


compiled?

^= combined


Thanks to all of you for your valuable help.

Regards,
Axel Dahmen

Axel Dahmen
Guest
 
Posts: n/a
#11: Oct 14 '06

re: Namespace question


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

Joe Kesselman
Guest
 
Posts: n/a
#12: Oct 14 '06

re: Namespace question


Axel Dahmen wrote:
Quote:
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.
Quote:
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.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Joe Kesselman
Guest
 
Posts: n/a
#13: Oct 14 '06

re: Namespace question


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."

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Axel Dahmen
Guest
 
Posts: n/a
#14: Oct 18 '06

re: Namespace question


I know, more detail than you wanted. And if you're lucky, more
Quote:
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

Closed Thread


Similar .NET Framework bytes