473,396 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Namespace question

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
Oct 11 '06 #1
13 2474
In article <eg**********@online.de>,
Axel Dahmen <NO*****@NoOneKnows.invalidwrote:
><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.
>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
Oct 11 '06 #2
Richard Tobin schrieb:
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)
Oct 11 '06 #3
In article <45***********************@authen.yellow.readfreen ews.net>,
Johannes Koch <ko**@w3development.dewrote:
>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
Oct 11 '06 #4
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 <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.
<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
Oct 11 '06 #5
Thanks, Richard, I'm still trying to understand XML, so your information is quite appreciated!
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?

Oct 14 '06 #6
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... ;)

Oct 14 '06 #7
Axel Dahmen schrieb:
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.
--
Johannes Koch
Spem in alium nunquam habui praeter in te, Deus Israel.
(Thomas Tallis, 40-part motet)
Oct 14 '06 #8
Axel Dahmen wrote:
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.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Oct 14 '06 #9
compiled?

^= combined
Thanks to all of you for your valuable help.

Regards,
Axel Dahmen

Oct 14 '06 #10
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

Oct 14 '06 #11
Axel Dahmen wrote:
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.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Oct 14 '06 #12
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
Oct 14 '06 #13
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

Oct 18 '06 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: John L. Clark | last post by:
I am curious as to the rationale, and effect, of having default namespaces not applying (directly) to attributes (see http://www.w3.org/TR/REC-xml-names/#defaulting). Given an attribute without a...
25
by: kj | last post by:
Consider the following XML document: <?xml version='1.0' encoding='UTF-8'?> <bar:foo xmlns:bar='someuri'> <baz/> </bar:foo> What namespace does baz belong to? What is this namespace bound...
3
by: Mike Dickens | last post by:
hi, i'm sure this has come up before but havn't managed to find an answer. if i have the following xslt <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet method="xml" version="1.0"...
6
by: clinton__bill | last post by:
Hi, I usually use "using namespace <namespace_name>" to reference a namespace. Today I run across a code, in its header file it has this, namespace SP1{ class C1; } While SP1::C1 is a...
2
by: Tony Johansson | last post by:
Hello! I'm reading a book about C++ and there is something that I don't understand so I ask you. Below I have the text from the book and the code from the file where main is located and some...
20
by: Patrick Guio | last post by:
Dear all, I have some problem with insertion operator together with namespace. I have a header file foo.h containing declaration of classes, typedefs and insertion operators for the typedefs in...
4
by: Programatix | last post by:
Hi, Normally, I would use Namespace for all the window forms I created. With VS 2005, the code generated by the designer is hidden using partial keyword. The question is, is there an efficient...
32
by: toolmaster | last post by:
Since many of the modern computer languages have built-in namespace features, I can't understand why not add this feature into standard C. I've heard many people complain of the lacking of...
3
by: CrazyJohn | last post by:
Hi guys, This is my first time posting question here, if I break any rules, please kindly point out. And I'm really glad to be a part of this community. Here is my question, Our lecturer...
17
by: Peng Yu | last post by:
Hi, I'm wondering if there is something in namespace like the 'private' keyword in class? I want to define some class or function that can only be used within that namespace. Thanks, Peng
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.