SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
InputSource is = new InputSource( new StringReader( xml ) );
XmlSaxHandler sh = XmlObject.Factory.newXmlSaxHandler();
xr.setFeature(
"http://xml.org/sax/features/namespace-prefixes",
true );
xr.setFeature(
"http://xml.org/sax/features/namespaces", true );
xr.setFeature(
"http://xml.org/sax/features/validation", false );
xr.setContentHandler( sh.getContentHandler() );
xr.setProperty(
"http://xml.org/sax/properties/lexical-handler",
sh.getLexicalHandler() );
xr.parse( is );
XmlObject x1 = sh.getObject();
XmlObject x2 = XmlObject.Factory.parse( xml );
Assert.assertTrue( x1.xmlText().equals( x2.xmlText() ) );
}