Skip to content

Commit

Permalink
Fix #47 write white-space events as character events
Browse files Browse the repository at this point in the history
  • Loading branch information
hxc9 committed Apr 25, 2018
1 parent bae0330 commit 3175647
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/ctc/wstx/sw/BaseStreamWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
23 changes: 17 additions & 6 deletions src/test/java/stax2/vwstream/W3CSchemaWrite23Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,30 @@ public class W3CSchemaWrite23Test
{
public void testSchemaValidatingCopy23() throws Exception
{
final String SCHEMA = "<?xml version='1.0' ?>\n"
+"<xs:schema elementFormDefault='unqualified'\n"
+" xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n"
+" <xs:element name='Document' type='xs:int'/>\n"
+"</xs:schema>";
final String CONTENT = "<Document>124</Document>";
final String SCHEMA = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<xs:schema elementFormDefault=\"unqualified\"\n" +
" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n" +
" <xs:element name=\"Document\">\n" +
" <xs:complexType>\n" +
" <xs:sequence>\n" +
" <xs:element name=\"Paragraph\" type=\"xs:string\"/>\n" +
" </xs:sequence>\n" +
" </xs:complexType>\n" +
" </xs:element>\n" +
"</xs:schema>";
final String CONTENT = "<Document>\n" +
" <Paragraph>Hello world!</Paragraph>\n" +
"</Document>";
final String DOC = "<?xml version='1.0' encoding='UTF-8'?>\n"+CONTENT;


StringWriter strw = new StringWriter();
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);
Expand Down

0 comments on commit 3175647

Please sign in to comment.