xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Simon McClenahan" <simon.mcclena...@stellent.com>
Subject Crimson questions
Date Fri, 08 Feb 2002 17:19:18 GMT
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

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 :
aNode).write(myStringWriter, XMLUtils.ENCODING_UTF_8);
				default :
					XmlDocument myXmlDocument =
(XmlDocument) aNode.getOwnerDocument();
myXmlDocument.createWriteContext(myStringWriter, 0));
		} 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() ?


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

View raw message