OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   JAXP's ID Transform failing to include namespace declarationattributes

[ Lists Home | Date Index | Thread Index ]

I've hit an unclear spot in the JAXP specification regarding the 
behavior of ID transforms. I think one thing should be happening and 
I know something else is happening but I'm not absolutely clear on 
whether or not I'm right. Clarification would be appreciated.

Suppose we want to use DOM and JAXP to produce the following document or its
equivalent, modulo white space and other insignificancies:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
  "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd";>
<svg xmlns="http://www.w3.org/2000/svg"/>

I claim the following code should do the trick, given that impl is a
DOMImplementation object:

       // Create the document
       DocumentType svgDOCTYPE = impl.createDocumentType(
        "svg", "-//W3C//DTD SVG 1.0//EN",
        "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd";
       );
       Document doc = impl.createDocument(
        "http://www.w3.org/2000/svg";, "svg", svgDOCTYPE);

       // Serialize the document onto System.out
       TransformerFactory xformFactory
        = TransformerFactory.newInstance();
       Transformer idTransform = xformFactory.newTransformer();
       Source input = new DOMSource(doc);
       Result output = new StreamResult(System.out);
       idTransform.transform(input, output);

However, what this in fact produces is

<?xml version="1.0" encoding="UTF-8"?>
<svg/>

There are two problems here:

1. The namespace is lost on the svg element.
2. The DOCTYPE declaration is lost.

The details are a little implementation dependent. SAXON and Xalan-J 
both give these results. However, Gnu JAXP can mask it because it has 
a bug that cancels out this bug.

I think both of these are problems with the idTransform. According to
the JAXP specification, p. 62, "If all that is desired is the simple
identity transformation of a source to a result, then 
TransformerFactory90 provides a newTransformer()93 method with no 
arguments. This method creates a Transformer that effectively copies 
the source to the result. This method may be used to create a DOM 
from SAX events or to create an XML or HTML stream from a DOM or SAX 
events."

This is less than perfectly clear on issues like whether it should
insert namespace attributes as necessary or include the DOCTYPE
declaration. However, I think that what's actually output really doesn't
strike me as a copy of the source to the result because a lot of
significant information has been lost.

Yes, I know that I could add the xmlns attribute, at least, manually.
However, I think this should be closer to the default behavior of
XMLSerializer where namespace declaration attributes are inserted
automatically in the stream as necessary.
-- 

+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo@metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+
|          The XML Bible, 2nd Edition (Hungry Minds, 2001)           |
|              http://www.ibiblio.org/xml/books/bible2/              |
|   http://www.amazon.com/exec/obidos/ISBN=0764547607/cafeaulaitA/   |
+----------------------------------+---------------------------------+
|  Read Cafe au Lait for Java News:  http://www.cafeaulait.org/      |
|  Read Cafe con Leche for XML News: http://www.ibiblio.org/xml/     |
+----------------------------------+---------------------------------+




 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS