List of usage examples for org.dom4j.io SAXReader setXMLReader
public void setXMLReader(XMLReader reader)
XMLReader
used to parse SAX events From source file:com.arc.xml.XmlProcessor.java
License:Open Source License
/** * Read a document from the source given the constraints defined by the meta-xml that was received in the * {@link #XmlProcessor(File) constructor}. * <P>/*ww w . j a va 2 s . c om*/ * The result is a document whose root element's <code>getData()</code> method will return the resulting data * obect. * @param source the XML file to be read. * @param instantiator the object for instantiating classes to form objects as we walk the XML document. * @param rootPackage the package relative to which classes are located. * @param ehandler error handler */ public Document read(InputSource source, IBuilderInstantiator instantiator, String rootPackage, ErrorHandler ehandler) throws SAXParseException, SAXException { mInstantiator = instantiator; mRootPackage = rootPackage; SAXReader reader = new MySAXReader(); if (mXMLReader != null) reader.setXMLReader(mXMLReader); mErrorHandler = ehandler; reader.setErrorHandler(ehandler); try { Document doc = reader.read(source); walk(doc); return doc; } catch (SAXParseException x) { if (x.getException() instanceof RuntimeException) throw (RuntimeException) x.getException(); if (mErrorHandler != null) mErrorHandler.error(x); else throw x; } catch (SAXException x) { // unwrap nested exceptions while (x.getException() != null) { Exception t = x.getException(); if (t instanceof SAXException && !(t instanceof SAXParseException)) x = (SAXException) t; else if (t instanceof RuntimeException) throw (RuntimeException) t; } if (mErrorHandler != null && x instanceof SAXParseException) { mErrorHandler.error((SAXParseException) x); } else throw x; } catch (DocumentException x) { throw new SAXException("DocumentException", x); } return null; }
From source file:org.jboss.ide.eclipse.as.core.extensions.descriptors.XMLDocumentRepository.java
License:Open Source License
private Document loadDocument(String fullpath) { Exception ex = null;//from ww w. j av a2 s . co m try { URL url; url = new File(fullpath).toURI().toURL(); SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); sp.getXMLReader().setFeature(LOAD_EXTERNAL_DTD_KEY, false); SAXReader reader = new SAXReader(false); reader.setXMLReader(sp.getXMLReader()); Document document = reader.read(url); return document; } catch (MalformedURLException e) { ex = e; } catch (ParserConfigurationException e) { ex = e; } catch (SAXException e) { ex = e; } catch (DocumentException e) { ex = e; } if (ex != null) { JBossServerCorePlugin.getDefault().getLog().log(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID, NLS.bind(Messages.loadXMLDocumentFailed, fullpath), ex)); } return null; }