xom-interest AT lists.ibiblio.org
Subject: XOM API for Processing XML with Java
List archive
Re: [XOM-interest] Getting the prefix of a namespace knowing the URI
- From: Elliotte Rusty Harold <elharo AT metalab.unc.edu>
- To: Laurent Bihanic <laurent.bihanic AT atosorigin.com>, XOM-interest <XOM-interest AT lists.ibiblio.org>
- Subject: Re: [XOM-interest] Getting the prefix of a namespace knowing the URI
- Date: Fri, 7 Feb 2003 09:49:12 -0500
At 1:45 PM +0100 2/7/03, Laurent Bihanic wrote:
Hi,
I need to pre-process an XML document to add some information to it. The elements to be added shall belong to a known namespace, already defined in the document. I want to avoid re-declaring this namespace with a new prefix and thus I need to retrieve the namespace prefix knowing the URI.
Wouldn't it be possible to just read the prefix from one of the known elements in that namespace? Would this solve your problem?
I found no way in XOM to do this but found a solution using XPath. Yet, it would be nice for XOM to provide a "native" solution.
I'm proposing to add a new getNamespacePrefix(String uri) method to Element (see below for a possible implementation). I tested it and it works fine once the getNamespaceURI bug I reported earlier fixed.
Maybe, but it's going to take some more convincing. My current thoughts on this are that at best, this is syntax sugar, and it's a nice bit of sugar. I agree it's good not to unnecessarily use two different prefixes for the same namespace. But using multiple prefixes should not cause any problems if the document is otherwise correct.
--
+-----------------------+------------------------+-------------------+
| 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/ |
+----------------------------------+---------------------------------+
-
[XOM-interest] Getting the prefix of a namespace knowing the URI,
Laurent Bihanic, 02/07/2003
-
Re: [XOM-interest] Getting the prefix of a namespace knowing the URI,
Elliotte Rusty Harold, 02/07/2003
-
Re: [XOM-interest] Getting the prefix of a namespace knowing the URI,
Laurent Bihanic, 02/07/2003
-
Re: [XOM-interest] Getting the prefix of a namespace knowing the URI,
Elliotte Rusty Harold, 02/07/2003
-
Re: [XOM-interest] Getting the prefix of a namespace knowing the URI,
Laurent Bihanic, 02/17/2003
- Re: [XOM-interest] Getting the prefix of a namespace knowing the URI, Elliotte Rusty Harold, 02/17/2003
-
Re: [XOM-interest] Getting the prefix of a namespace knowing the URI,
Laurent Bihanic, 02/17/2003
-
Re: [XOM-interest] Getting the prefix of a namespace knowing the URI,
Elliotte Rusty Harold, 02/07/2003
-
Re: [XOM-interest] Getting the prefix of a namespace knowing the URI,
Laurent Bihanic, 02/07/2003
- Re: [XOM-interest] Getting the prefix of a namespace knowing the URI, Elliotte Rusty Harold, 02/07/2003
-
Re: [XOM-interest] Getting the prefix of a namespace knowing the URI,
Elliotte Rusty Harold, 02/07/2003
Archive powered by MHonArc 2.6.24.