Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] Getting the prefix of a namespace knowing the URI

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Elliotte Rusty Harold <elharo AT metalab.unc.edu>
  • To: Laurent Bihanic <laurent.bihanic AT atosorigin.com>
  • Cc: XOM-interest <XOM-interest AT lists.ibiblio.org>
  • Subject: Re: [XOM-interest] Getting the prefix of a namespace knowing the URI
  • Date: Mon, 17 Feb 2003 13:06:02 -0500

At 6:52 PM +0100 2/17/03, Laurent Bihanic wrote:
Why is that unusual? Working with the URI alone and ignoring the prefix used in a document instance is just what XPath does and what XOM provides with getChildElement(name, uri).

What's unusual is not working with the URI alone. XOM fully supports that. What's unusual is wanting to find out the prefix.

So XOM (and XPath) provides me ways to access elements and attribute ignoring the namespace prefix used but to modify the document contents I have to either redeclare the namespace using an arbitrary (possibly conflicting) prefix or develop some low-level code to find the namespace declaration.

As I said before, almost all the time if the namespace is used at all in the input document, there'll be an obvious element somewhere from which you can read the prefix; perhaps the root, perhaps something else. I don't think it's that hard to get now.

I've thought this one through, and it just doesn't cross my 80/20 line. If you want to move me, you're going to have to come up with some pretty convincing and explicit use-cases.

--

+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo AT metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+
| Processing XML with Java (Addison-Wesley, 2002) |
| http://www.cafeconleche.org/books/xmljava |
| http://www.amazon.com/exec/obidos/ISBN%3D0201771861/cafeaulaitA |
+----------------------------------+---------------------------------+
| Read Cafe au Lait for Java News: http://www.cafeaulait.org/ |
| Read Cafe con Leche for XML News: http://www.cafeconleche.org/ |
+----------------------------------+---------------------------------+
From mmceniry AT itsc.uah.edu Mon Feb 17 15:18:22 2003
Return-Path: <mmceniry AT itsc.uah.edu>
Delivered-To: xom-interest AT lists.ibiblio.org
Received: from home.itsc.uah.edu (home.itsc.uah.edu [146.229.234.51])
by happyhouse.metalab.unc.edu (Postfix) with ESMTP id 4E3F42001C
for <XOM-interest AT lists.ibiblio.org>;
Mon, 17 Feb 2003 15:18:22 -0500 (EST)
X-MimeOLE: Produced By Microsoft Exchange V6.0.5762.3
content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: text/plain;
charset="US-ASCII"
Content-Transfer-Encoding: quoted-printable
Subject: RE: [XOM-interest] Getting the prefix of a namespace knowing the URI
Date: Mon, 17 Feb 2003 14:19:33 -0600
Message-ID: <E05C39DBFF41854D9DC891EDC9DAE58A626B85 AT home.itsc.uah.edu>
X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [XOM-interest] Getting the prefix of a namespace knowing the
URI
Thread-Index: AcLWr7+TN++NHLpkRDCdTVSSVnWkhgACNZQA
From: "McEniry, Michael" <mmceniry AT itsc.uah.edu>
To: "XOM-interest" <XOM-interest AT lists.ibiblio.org>
X-BeenThere: xom-interest AT lists.ibiblio.org
X-Mailman-Version: 2.1.1
Precedence: list
List-Id: <xom-interest.lists.ibiblio.org>
List-Unsubscribe: <http://lists.ibiblio.org/mailman/listinfo/xom-interest>,
<mailto:xom-interest-request AT lists.ibiblio.org?subject=unsubscribe>
List-Archive: <https://lists.ibiblio.org/sympa/arc/xom-interest>
List-Post: <mailto:xom-interest AT lists.ibiblio.org>
List-Help: <mailto:sympa AT lists.ibiblio.org?subject=HELP>
List-Subscribe: <http://lists.ibiblio.org/mailman/listinfo/xom-interest>,
<mailto:xom-interest-request AT lists.ibiblio.org?subject=subscribe>
X-List-Received-Date: Mon, 17 Feb 2003 20:18:22 -0000

Elliotte Rusty Harold wrote:
At 6:52 PM +0100 2/17/03, Laurent Bihanic wrote:
>Why is that unusual? Working with the URI alone and ignoring the=20
>prefix used in a document instance is just what XPath does and what=20
>XOM provides with getChildElement(name, uri).
=20
What's unusual is not working with the URI alone. XOM fully supports=20
that. What's unusual is wanting to find out the prefix.

Perhaps someone has mentioned this before on the list, but I think=20
what counts as "usual" depends on whether one is reading XML or writing=20
it. When reading XML, once the parsing and validation is complete, one=20
is more concerned that a namespace is tied to a particular URI than
which=20
non-universal identifier is used as a prefix. When writing XML, even=20
though the URI is still the essential part of a namespace, one must=20
specify a prefix, because that is how XML works.

A namespace prefix is similar to a CDATA section in that it is strictly=20
a syntactic device and not a semantic one. CDATA is "syntactic sugar",=20
since one can use a different way to produce the same semantic result.=20
However, a namespace prefix is more like "syntactic fiber", since there=20
really is no other way to produce the same semantic result, given=20
current XML syntax.

Perhaps one approach is to treat namespace prefix like character
encoding.=20
Make it the responsibility of the serializer. One must specify a
namespace=20
map (URI -> prefix) as a parameter just as must specify "UTF-8". If a=20
namespace map does not include a prefix for a particular URI, then the=20
serializer could use arbitrary prefixes (eg, "ns1", "ns2", etc) or could

report an exception.

-- michael mceniry

PS: In spite of the excessive verbosity and utter unreadability, I want
the=20
following XML to be considered well-formed, just for a sense of
consistency,=20
since this is how it works semantically:

<"http://www.w3.org/1999/XSL/Transform":stylesheet version=3D"1.0">
<"http://www.w3.org/1999/XSL/Transform":template match=3D"doc">
<"http://www.w3.org/TR/xhtml1/strict":html>
<"http://www.w3.org/TR/xhtml1/strict":head>
<"http://www.w3.org/TR/xhtml1/strict":title>
<"http://www.w3.org/1999/XSL/Transform":value-of
select=3D"title"/>
</"http://www.w3.org/TR/xhtml1/strict":title>
</"http://www.w3.org/TR/xhtml1/strict":head>
<"http://www.w3.org/TR/xhtml1/strict":body>
<"http://www.w3.org/1999/XSL/Transform":apply-templates/>
</"http://www.w3.org/TR/xhtml1/strict":body>
</"http://www.w3.org/TR/xhtml1/strict":html>
</"http://www.w3.org/1999/XSL/Transform":template>
</"http://www.w3.org/1999/XSL/Transform":stylesheet>
From elharo AT metalab.unc.edu Mon Feb 17 15:31:17 2003
Return-Path: <elharo AT metalab.unc.edu>
Delivered-To: xom-interest AT lists.ibiblio.org
Received: from mail.speakeasy.net (mail14.speakeasy.net [216.254.0.214])
by happyhouse.metalab.unc.edu (Postfix) with ESMTP id D0C5D2001C
for <XOM-interest AT lists.ibiblio.org>;
Mon, 17 Feb 2003 15:31:16 -0500 (EST)
Received: (qmail 20444 invoked from network); 17 Feb 2003 20:32:32 -0000
Received: from unknown (HELO [192.168.254.4]) ([216.254.85.72])
(envelope-sender <elharo AT metalab.unc.edu>)
by mail14.speakeasy.net (qmail-ldap-1.03) with SMTP
for <mmceniry AT itsc.uah.edu>; 17 Feb 2003 20:32:32 -0000
Mime-Version: 1.0
X-Sender: elharo AT mail.ibiblio.org
Message-Id: <p04330102ba76f523eba0@[192.168.254.4]>
In-Reply-To: <E05C39DBFF41854D9DC891EDC9DAE58A626B85 AT home.itsc.uah.edu>
References: <E05C39DBFF41854D9DC891EDC9DAE58A626B85 AT home.itsc.uah.edu>
Date: Mon, 17 Feb 2003 15:29:14 -0500
To: "McEniry, Michael" <mmceniry AT itsc.uah.edu>,
"XOM-interest" <XOM-interest AT lists.ibiblio.org>
From: Elliotte Rusty Harold <elharo AT metalab.unc.edu>
Subject: RE: [XOM-interest] Getting the prefix of a namespace knowing the URI
Content-Type: text/plain; charset="us-ascii" ; format="flowed"
X-BeenThere: xom-interest AT lists.ibiblio.org
X-Mailman-Version: 2.1.1
Precedence: list
List-Id: <xom-interest.lists.ibiblio.org>
List-Unsubscribe: <http://lists.ibiblio.org/mailman/listinfo/xom-interest>,
<mailto:xom-interest-request AT lists.ibiblio.org?subject=unsubscribe>
List-Archive: <https://lists.ibiblio.org/sympa/arc/xom-interest>
List-Post: <mailto:xom-interest AT lists.ibiblio.org>
List-Help: <mailto:sympa AT lists.ibiblio.org?subject=HELP>
List-Subscribe: <http://lists.ibiblio.org/mailman/listinfo/xom-interest>,
<mailto:xom-interest-request AT lists.ibiblio.org?subject=subscribe>
X-List-Received-Date: Mon, 17 Feb 2003 20:31:17 -0000

At 2:19 PM -0600 2/17/03, McEniry, Michael wrote:
A namespace prefix is similar to a CDATA section in that it is strictly
a syntactic device and not a semantic one. CDATA is "syntactic sugar",
since one can use a different way to produce the same semantic result.
However, a namespace prefix is more like "syntactic fiber", since there
really is no other way to produce the same semantic result, given
current XML syntax.

Which is why XOM lets you specify the prefix. In fact, it requires you to do so. It does not assign them randomly.

XOM also lets you find out which prefix any given element or attribute has.

The question is only whether there should be a convenience method that walks up the tree to find the nearest prefix mapped to a given URI. (Here's another monkey wrench for that idea: there may be more than one such prefix in scope, even on a single element so the method should return a String array, not a single String.) You can do this now. XOM gives you everything you need. There's non information missing. We're just arguing about whether I should put this into the core or not.

Perhaps one approach is to treat namespace prefix like character
encoding.
Make it the responsibility of the serializer. One must specify a
namespace
map (URI -> prefix) as a parameter just as must specify "UTF-8". If a
namespace map does not include a prefix for a particular URI, then the
serializer could use arbitrary prefixes (eg, "ns1", "ns2", etc) or could

report an exception.

No. The prefixes are part of the element names and are reported and stored as such. This is not just an artifact of serialization so it can't really be changed by the Serializer.

Yes, this whole shebang with prefixes vs. URIs is ugly, but it's ugly because XML is ugly here. XOM can't and won't pretend XML is simpler than it is.


PS: In spite of the excessive verbosity and utter unreadability, I want
the
following XML to be considered well-formed, just for a sense of
consistency,
since this is how it works semantically:

But it's not well-formed. Sorry about that, but I didn't make up these rules. I just follow them. :-(

<"http://www.w3.org/1999/XSL/Transform":stylesheet version="1.0">
<"http://www.w3.org/1999/XSL/Transform":template match="doc">
<"http://www.w3.org/TR/xhtml1/strict":html>
<"http://www.w3.org/TR/xhtml1/strict":head>
<"http://www.w3.org/TR/xhtml1/strict":title>
<"http://www.w3.org/1999/XSL/Transform":value-of
select="title"/>
</"http://www.w3.org/TR/xhtml1/strict":title>
</"http://www.w3.org/TR/xhtml1/strict":head>
<"http://www.w3.org/TR/xhtml1/strict":body>
<"http://www.w3.org/1999/XSL/Transform":apply-templates/>
</"http://www.w3.org/TR/xhtml1/strict":body>
</"http://www.w3.org/TR/xhtml1/strict":html>
</"http://www.w3.org/1999/XSL/Transform":template>
</"http://www.w3.org/1999/XSL/Transform":stylesheet>

--

+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo AT metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+
| Processing XML with Java (Addison-Wesley, 2002) |
| http://www.cafeconleche.org/books/xmljava |
| http://www.amazon.com/exec/obidos/ISBN%3D0201771861/cafeaulaitA |
+----------------------------------+---------------------------------+
| Read Cafe au Lait for Java News: http://www.cafeaulait.org/ |
| Read Cafe con Leche for XML News: http://www.cafeconleche.org/ |
+----------------------------------+---------------------------------+
From rogers AT cadenhead.org Tue Feb 18 17:23:31 2003
Return-Path: <rogers AT cadenhead.org>
Delivered-To: xom-interest AT lists.ibiblio.org
Received: from imf22bis.bellsouth.net (mail022.mail.bellsouth.net
[205.152.58.62])
by happyhouse.metalab.unc.edu (Postfix) with ESMTP id C02652001F
for <xom-interest AT lists.ibiblio.org>;
Tue, 18 Feb 2003 17:23:30 -0500 (EST)
Received: from ZEUS ([66.20.159.8]) by imf22bis.bellsouth.net
(InterMail vM.5.01.04.25 201-253-122-122-125-20020815) with SMTP
id <20030218222641.MNAW8977.imf22bis.bellsouth.net@ZEUS>
for <xom-interest AT lists.ibiblio.org>;
Tue, 18 Feb 2003 17:26:41 -0500
From: Rogers Cadenhead <rogers AT cadenhead.org>
To: XOM-Interest <xom-interest AT lists.ibiblio.org>
X-Mailer: PocoMail 2.63 (1077) - Licensed Version
Date: Tue, 18 Feb 2003 17:24:41 -0500
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Message-Id: <20030218222641.MNAW8977.imf22bis.bellsouth.net@ZEUS>
Subject: [XOM-interest] Linux Magazine article on XOM
X-BeenThere: xom-interest AT lists.ibiblio.org
X-Mailman-Version: 2.1.1
Precedence: list
List-Id: <xom-interest.lists.ibiblio.org>
List-Unsubscribe: <http://lists.ibiblio.org/mailman/listinfo/xom-interest>,
<mailto:xom-interest-request AT lists.ibiblio.org?subject=unsubscribe>
List-Archive: <https://lists.ibiblio.org/sympa/arc/xom-interest>
List-Post: <mailto:xom-interest AT lists.ibiblio.org>
List-Help: <mailto:sympa AT lists.ibiblio.org?subject=HELP>
List-Subscribe: <http://lists.ibiblio.org/mailman/listinfo/xom-interest>,
<mailto:xom-interest-request AT lists.ibiblio.org?subject=subscribe>
X-List-Received-Date: Tue, 18 Feb 2003 22:23:31 -0000

I have an article in the March 2003 issue of Linux Magazine that=

covers XOM. I just got it in the mail this afternoon, so it will=

probably be in stores within a week or two. (It won't be online=
for several months.)

I have a few questions from working with version 1.0d8 to write=
the piece, but I'll hold off until I can see if they still apply to 1.0d10.

Overall, I found XOM to be an amazingly well-organized, intuitive=
API that's easy to learn and to use. I like how it reinforces good practices and provides insight about XML -- such as the lack of whitespace when XML is produced without a serializer and the identical treatment of text whether it consists of character entities, CDATA sections, or regular characters.

I can't compare it to JDOM, but it's appreciably more pleasant to=

work with than the Simple API for XML Processing.
--
Rogers Cadenhead, rogers AT cadenhead.org on 02/18/2003
Weblog: http://www.cadenhead.org/workbench





Archive powered by MHonArc 2.6.24.

Top of Page