Search in sources :

Example 1 with XMLSerializerListener

use of org.apache.pivot.xml.XMLSerializerListener in project pivot by apache.

the class XMLSerializerTest method equalsTest.

@Test
public void equalsTest() throws IOException, SerializationException {
    XMLSerializer xmlSerializer = new XMLSerializer();
    XMLSerializerListener xmlSerializerListener = new XMLSerializerListener() {

        @Override
        public void beginElement(XMLSerializer xmlSerializerArgument, Element element) {
            System.out.println("Begin element: " + element);
        }

        @Override
        public void endElement(XMLSerializer xmlSerializerArgument) {
            System.out.println("End element");
        }

        @Override
        public void readTextNode(XMLSerializer xmlSerializerArgument, TextNode textNode) {
            System.out.println("Read text node: " + textNode);
        }
    };
    xmlSerializer.getXMLSerializerListeners().add(xmlSerializerListener);
    Element root1 = xmlSerializer.readObject(getClass().getResourceAsStream("sample.xml"));
    assertNotNull(root1);
    xmlSerializer.getXMLSerializerListeners().remove(xmlSerializerListener);
    Element root2 = xmlSerializer.readObject(getClass().getResourceAsStream("sample.xml"));
    assertNotNull(root2);
}
Also used : XMLSerializer(org.apache.pivot.xml.XMLSerializer) XMLSerializerListener(org.apache.pivot.xml.XMLSerializerListener) Element(org.apache.pivot.xml.Element) TextNode(org.apache.pivot.xml.TextNode) Test(org.junit.Test)

Aggregations

Element (org.apache.pivot.xml.Element)1 TextNode (org.apache.pivot.xml.TextNode)1 XMLSerializer (org.apache.pivot.xml.XMLSerializer)1 XMLSerializerListener (org.apache.pivot.xml.XMLSerializerListener)1 Test (org.junit.Test)1