3131
3232public class AxiomHandlerTest extends XMLTestCase {
3333
34- private static final String XML_1 = "<?xml version='1.0' encoding='UTF-8'?>" + "<?pi content?>" +
35- "<root xmlns='namespace'>" +
36- "<prefix:child xmlns:prefix='namespace2' xmlns:prefix2='namespace3' prefix2:attr='value'>content</prefix:child>" +
37- "</root>" ;
34+ private static final String XML_1 =
35+ "<?xml version='1.0' encoding='UTF-8'?>" + "<?pi content?>" + "< root xmlns='namespace'>" +
36+ "<prefix:child xmlns:prefix='namespace2' xmlns:prefix2='namespace3' prefix2:attr='value'>content</prefix:child>" +
37+ "</root>" ;
3838
39- private static final String XML_2_EXPECTED = "<?xml version='1.0' encoding='UTF-8'?>" + "<root xmlns='namespace'>" +
40- "<child xmlns='namespace2' />" + "</root>" ;
39+ private static final String XML_2_EXPECTED =
40+ "<?xml version='1.0' encoding='UTF-8'?>" + "<root xmlns='namespace'>" + "<child xmlns='namespace2' />" +
41+ "</root>" ;
4142
4243 private static final String XML_2_SNIPPET =
4344 "<?xml version='1.0' encoding='UTF-8'?>" + "<child xmlns='namespace2' />" ;
4445
46+ private static final String XML_3_ENTITY =
47+ "<predefined-entity-reference><>&"'</predefined-entity-reference>" ;
48+
4549 private AxiomHandler handler ;
4650
4751 private OMDocument result ;
@@ -87,4 +91,14 @@ public void testContentHandlerElement() throws Exception {
8791 result .serialize (bos );
8892 assertXMLEqual ("Invalid result" , XML_2_EXPECTED , bos .toString ("UTF-8" ));
8993 }
94+
95+ public void testContentHandlerPredefinedEntityReference () throws Exception {
96+ handler = new AxiomHandler (result , factory );
97+ xmlReader .setContentHandler (handler );
98+ xmlReader .setProperty ("http://xml.org/sax/properties/lexical-handler" , handler );
99+ xmlReader .parse (new InputSource (new StringReader (XML_3_ENTITY )));
100+ ByteArrayOutputStream bos = new ByteArrayOutputStream ();
101+ result .serialize (bos );
102+ assertXMLEqual ("Invalid result" , XML_3_ENTITY , bos .toString ("UTF-8" ));
103+ }
90104}
0 commit comments