From 3175647b0eba4289369e296171dee5ad11444261 Mon Sep 17 00:00:00 2001 From: Alexis Hafner Date: Wed, 25 Apr 2018 11:47:11 +0200 Subject: [PATCH] Fix #47 write white-space events as character events --- .../com/ctc/wstx/sw/BaseStreamWriter.java | 2 +- .../stax2/vwstream/W3CSchemaWrite23Test.java | 23 ++++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/ctc/wstx/sw/BaseStreamWriter.java b/src/main/java/com/ctc/wstx/sw/BaseStreamWriter.java index a066d5ec..7ebf62e6 100644 --- a/src/main/java/com/ctc/wstx/sw/BaseStreamWriter.java +++ b/src/main/java/com/ctc/wstx/sw/BaseStreamWriter.java @@ -803,7 +803,7 @@ public void copyEventFromReader(XMLStreamReader2 sr, boolean preserveEventData) // 28-Mar-2017, tatu: Various optimization do not work well when validation so: if (mValidator != null) { - writeCData(sr.getText()); + writeCharacters(sr.getText()); } else { sr.getText(wrapAsRawWriter(), preserveEventData); } diff --git a/src/test/java/stax2/vwstream/W3CSchemaWrite23Test.java b/src/test/java/stax2/vwstream/W3CSchemaWrite23Test.java index 940698a4..7b6f6bd8 100644 --- a/src/test/java/stax2/vwstream/W3CSchemaWrite23Test.java +++ b/src/test/java/stax2/vwstream/W3CSchemaWrite23Test.java @@ -10,12 +10,20 @@ public class W3CSchemaWrite23Test { public void testSchemaValidatingCopy23() throws Exception { - final String SCHEMA = "\n" -+"\n" -+" \n" -+""; - final String CONTENT = "124"; + final String SCHEMA = "\n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + final String CONTENT = "\n" + + " Hello world!\n" + + ""; final String DOC = "\n"+CONTENT; @@ -23,6 +31,9 @@ public void testSchemaValidatingCopy23() throws Exception XMLStreamWriter2 xmlWriter = getSchemaValidatingWriter(strw, SCHEMA, false); XMLStreamReader2 xmlReader = constructNsStreamReader(DOC, false); + // For this test we need validation, otherwise the reader returns characters events instead of white-space events. + xmlReader.validateAgainst(parseW3CSchema(SCHEMA)); + while (xmlReader.hasNext()) { /*int type =*/ xmlReader.next(); xmlWriter.copyEventFromReader(xmlReader, true);