public static void main ( String [ ] args ) throws SAXException , IOException { // create our expression context ELContext context = new SimpleContext ( ) ; // set value for top-level property "home" context . getELResolver ( ) . setValue ( context , null , "home" , "/foo/bar" ) ; // create our filtered reader XMLReader reader = new XMELFilter ( XMLReaderFactory . createXMLReader ( ) , context ) ; // simple test content handler to print elements and attributes to stdout reader . setContentHandler ( new DefaultHandler ( ) { @ Override public void startElement ( String uri , String localName , String qName , Attributes attributes ) { System . out . println ( "start " + localName ) ; for ( int i = 0 ; i < attributes . getLength ( ) ; i ++ ) { System . out . println ( " @" + attributes . getLocalName ( i ) + " = " + attributes . getValue ( i ) ) ; } } @ Override public void endElement ( String uri , String localName , String qName ) { System . out . println ( "end " + localName ) ; } @ Override public void characters ( char [ ] ch , int start , int length ) throws SAXException { System . out . println ( "text: " + new String ( ch , start , length ) ) ; } } ) ; // parse our test input and watch the evaluated attributes and template text String xml = "<test>foo<math>1+2=${1+2}</math><config file='${home}/config.xml'/>bar</test>" ; reader . parse ( new InputSource ( new StringReader ( xml ) ) ) ; }
Usage example .