You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xml.apache.org by Simon McClenahan <si...@stellent.com> on 2002/02/08 18:19:18 UTC
Crimson questions
I want to bundle a JAXP compliant XML parser with my application, with
the requirement that the jar file is as small as possible. From what I
can tell, between Crimson, Xerces1 and Xerces2, I am using Crimson
because of its smaller jar size. However, if there is a way to
distribute Xerces2 without all the classes that I don't use so that it
reduces the size of the jar, that would be preferable.
Now that I'm using Crimson, I have a technical question about
serialization, and apparently this list is the only forum for Crimson
discussion.
I can serialize a Document fine, but I haven't figured out how to
serialize any other type of DOM Node. My code is:
----------------------------------------------------------------------
public static String serializeToString(Node aNode) {
String myResult = null;
// Crimson implementation
StringWriter myStringWriter = new StringWriter();
short myNodeType = aNode.getNodeType();
try {
switch (myNodeType) {
case Node.DOCUMENT_NODE :
((XmlDocument)
aNode).write(myStringWriter, XMLUtils.ENCODING_UTF_8);
break;
default :
XmlDocument myXmlDocument =
(XmlDocument) aNode.getOwnerDocument();
myXmlDocument.writeChildrenXml(
myXmlDocument.createWriteContext(myStringWriter, 0));
break;
}
} catch (IOException e) {
String myMsg = "Unable to serialize DOM Node: "
+ e.getMessage();
throw new RuntimeException(myMsg);
}
myResult = myStringWriter.toString();
return myResult;
}
----------------------------------------------------------------------
However, the default non-Document case returns an empty String. From
what I can tell this is because Crimson does not see any children of the
given DOM Node and exits early without serializing anything.
Specifically, I would like to serialize an Element. Do I have to write a
hack that creates a new XmlDocument, import the Element, then serialize
the XmlDocument without the XML header information currently hard coded
in XmlDocument.write() ?
cheers,
Simon
---------------------------------------------------------------------
In case of troubles, e-mail: webmaster@xml.apache.org
To unsubscribe, e-mail: general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org
Re: Crimson questions
Posted by Edwin Goei <ed...@sun.com>.
Simon McClenahan wrote:
>
> I want to bundle a JAXP compliant XML parser with my application, with
> the requirement that the jar file is as small as possible. From what I
> can tell, between Crimson, Xerces1 and Xerces2, I am using Crimson
> because of its smaller jar size. However, if there is a way to
> distribute Xerces2 without all the classes that I don't use so that it
> reduces the size of the jar, that would be preferable.
>
> Now that I'm using Crimson, I have a technical question about
> serialization, and apparently this list is the only forum for Crimson
> discussion.
The serialization interface you are using will tie your app to Crimson.
Another way is to use javax.xml.transform, but that would conflict w/
keeping your app small. Another option is to require running on JDK 1.4
which includes JAXP within it so you would not need to bundle anything
w/ your app. Also see the JAXP FAQ at
http://xml.apache.org/~edwingo/jaxp-faq.html#output for more info. That
page also has pointers to other non-Apache parsers.
>
> I can serialize a Document fine, but I haven't figured out how to
> serialize any other type of DOM Node. My code is:
>
> ----------------------------------------------------------------------
> public static String serializeToString(Node aNode) {
> String myResult = null;
> // Crimson implementation
> StringWriter myStringWriter = new StringWriter();
> short myNodeType = aNode.getNodeType();
> try {
> switch (myNodeType) {
> case Node.DOCUMENT_NODE :
> ((XmlDocument)
> aNode).write(myStringWriter, XMLUtils.ENCODING_UTF_8);
> break;
> default :
> XmlDocument myXmlDocument =
> (XmlDocument) aNode.getOwnerDocument();
> myXmlDocument.writeChildrenXml(
>
> myXmlDocument.createWriteContext(myStringWriter, 0));
> break;
> }
> } catch (IOException e) {
> String myMsg = "Unable to serialize DOM Node: "
> + e.getMessage();
> throw new RuntimeException(myMsg);
> }
> myResult = myStringWriter.toString();
> return myResult;
> }
> ----------------------------------------------------------------------
>
> However, the default non-Document case returns an empty String. From
> what I can tell this is because Crimson does not see any children of the
> given DOM Node and exits early without serializing anything.
>
> Specifically, I would like to serialize an Element. Do I have to write a
> hack that creates a new XmlDocument, import the Element, then serialize
> the XmlDocument without the XML header information currently hard coded
> in XmlDocument.write() ?
If you or anyone else wants to figure it out, I'd start looking at the
code in org/apache/crimson/tree/ElementNode and ElementNode2.java.
-Edwin
---------------------------------------------------------------------
In case of troubles, e-mail: webmaster@xml.apache.org
To unsubscribe, e-mail: general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org