You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Elliotte Rusty Harold <el...@metalab.unc.edu> on 2001/12/31 23:07:13 UTC
JAXP/DOM/TrAX failure to handle namespaces and DOCTYPE properly in ID
transform
Suppose we want to use DOM to produce the following document or its
equivalent, modulo white space and other insignifcancies:
<?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.
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 |
+-----------------------+------------------------+-------------------+
| Java I/O (O'Reilly & Associates, 1999) |
| http://www.ibiblio.org/javafaq/books/javaio/ |
| http://www.amazon.com/exec/obidos/ISBN=1565924851/cafeaulaitA/ |
+----------------------------------+---------------------------------+
| Read Cafe au Lait for Java News: http://www.cafeaulait.org/ |
| Read Cafe con Leche for XML News: http://www.ibiblio.org/xml/ |
+----------------------------------+---------------------------------+
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org
Re: JAXP/DOM/TrAX failure to handle namespaces and DOCTYPE properly in
ID transform
Posted by Edwin Goei <ed...@sun.com>.
Elliotte Rusty Harold wrote:
>
> Suppose we want to use DOM to produce the following document or its
> equivalent, modulo white space and other insignifcancies:
> [snip]
>
> 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.
Yes, I would agree with your above points. I would guess that is may be
a Xalan bug since the code for the TransformerFactory implementation and
the serializer probably is in Xalan. I'd post this problem to
Xalan-dev.
-Edwin
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org