[jdom-interest] XmlOutputter - printNamespace - NO_NAMESPACE outputs xmlns="", bug?
John Jefferson
surfer97301 at yahoo.com
Wed Jul 2 15:06:22 PDT 2003
Actually I do something like this:
String xml = "<root> <child1> data </child1> </root>";
StringReader sr = new StringReader(xml);
XMLReader xr =
XMLReaderFactory.createXMLReader(PARSER)
xr.parse(new InputSource(fr));
then when sax says I am at the root element I do the
following:
public void endElement (String uri, String
localName, String qName)
throws SAXException
{
if (stack.empty()) {
atRoot = true;
}
if (atRoot) {
handleRoot(Element ele);
}
handleRoot is the original code snippet.
So I am not really adding the nodes. They already
exist and should be in the default namespace.
Can anyone explain the logic in the orginal code
fragment? I just recreated the xmloutputter class and
changed the logic to :
if ( (!(ns == Namespace.NO_NAMESPACE) &&
(namespaces.getURI("") == null))) {
printNamespace(ns, out, namespaces);
}
This seems to work and is what I want.
--- Eric VERGNAUD <eric.vergnaud at wanadoo.fr> wrote:
> le 2/07/03 23:31, John Jefferson à
> surfer97301 at yahoo.com a écrit :
>
> >
> > Hi,
> >
> > My problem is that when outputing xml some of the
> > children of my document are given blank
> namespaces.
> >
> > For instance <root> <child1
> xmlns=""></child1></root>
> >
> > The reason for this is in the method below and
> occurs
> > because the namespace is NO_NAMESPACE but
> > namespaces.getURI("") is not null.
> >
> > This is bad because I set the default namespace of
> the
> > root element to a value - the value of
> > namespaces.getURI("") - but the children are then
> > defined to be using a different namespace the
> xmlns of
> > "".
> >
>
> Since I ran into exactly the same problem a few
> weeks ago, here is the
> answer:
>
> - you need to set each child's namespace to your
> root namespace. This will
> end up with:
>
> <root xmlns="root"> <child1> data </child1> </root>
>
> - this is because there seems to be no concept of a
> default namespace when
> creating a document, while there is one when reading
>
> - looks like I'm not the only one to think this is
> counter-intuitive, so
> maybe it could be discussed on this list
>
> Eric
>
> _______________________________________________
> To control your jdom-interest membership:
>
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com
__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com
More information about the jdom-interest
mailing list