From 4b7a17ba308f6645545788e95d604b8f0ed71d67 Mon Sep 17 00:00:00 2001 From: Harald Kuhr Date: Sun, 7 Feb 2010 17:57:38 +0100 Subject: [PATCH 1/4] Fixed bug that XMLSerializer output wrong processing instructions. --- .../com/twelvemonkeys/xml/XMLSerializer.java | 40 +++++++++++++------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/twelvemonkeys-core/src/main/java/com/twelvemonkeys/xml/XMLSerializer.java b/twelvemonkeys-core/src/main/java/com/twelvemonkeys/xml/XMLSerializer.java index ae9d2e24..b2488300 100755 --- a/twelvemonkeys-core/src/main/java/com/twelvemonkeys/xml/XMLSerializer.java +++ b/twelvemonkeys-core/src/main/java/com/twelvemonkeys/xml/XMLSerializer.java @@ -51,13 +51,13 @@ public class XMLSerializer { // Main problem: Sun's Java 5 does not have LS 3.0 support // This class has no dependencies, which probably makes it more useful + // TODO: Don't insert initial and ending line-break for text-nodes + // TODO: Support not inserting line-breaks, to preserve space // TODO: Support line breaking (at configurable width) - // TODO: Support skipping XML declaration? // TODO: Support standalone? // TODO: Support more than version 1.0? // TODO: Consider using IOException to communicate trouble, rather than RTE, // to be more compatible... - // TODO: Support not inserting line-breaks, to preserve space // TODO: Idea: Create a SerializationContext that stores attributes on // serialization, to keep the serialization thread-safe @@ -152,7 +152,7 @@ public class XMLSerializer { writeComment(pOut, pNode, pContext); break; case Node.PROCESSING_INSTRUCTION_NODE: - writeProcessingInstruction(pOut, pNode); + writeProcessingInstruction(pOut, (ProcessingInstruction) pNode); break; case Node.ATTRIBUTE_NODE: throw new IllegalArgumentException("Malformed input Document: Attribute nodes should only occur inside Element nodes"); @@ -167,9 +167,16 @@ public class XMLSerializer { } } - private void writeProcessingInstruction(final PrintWriter pOut, final Node pNode) { + private void writeProcessingInstruction(final PrintWriter pOut, final ProcessingInstruction pNode) { pOut.print("\n"); } @@ -180,8 +187,11 @@ public class XMLSerializer { pOut.print(maybeEscapeElementValue(value)); } else if (!StringUtil.isEmpty(value)) { - indentToLevel(pOut, pContext); - pOut.println(maybeEscapeElementValue(value.trim())); + String escapedValue = maybeEscapeElementValue(value.trim()); + //if (escapedValue.length() + (pContext.level * pContext.indent.length()) > 78) { + indentToLevel(pOut, pContext); + //} + pOut.println(escapedValue); } } @@ -219,7 +229,7 @@ public class XMLSerializer { } String value = pNode.getNodeValue(); - validateCommenValue(value); + validateCommentValue(value); if (value.startsWith(" ")) { pOut.print("