List of usage examples for org.dom4j.io SAXReader getXMLReader
public XMLReader getXMLReader() throws SAXException
From source file:com.cladonia.xml.XMLUtilities.java
License:Open Source License
/** * Creates a new SAXReader.//from ww w .j a va 2 s. c o m * * @param validate when true the reader validates the input. * * @return the reader. */ public static SAXReader createReader(boolean validate, boolean loadExternalDTD) { SAXReader reader = new SAXReader(XDocumentFactory.getInstance(), validate); reader.setStripWhitespaceText(false); reader.setMergeAdjacentText(true); // reader.setMergeAdjacentText( true); if (!validate) { reader.setIncludeExternalDTDDeclarations(false); reader.setIncludeInternalDTDDeclarations(true); try { if (loadExternalDTD) { reader.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", true); // System.out.println( "http://apache.org/xml/features/nonvalidating/load-external-dtd = "+reader.getXMLReader().getFeature( "http://apache.org/xml/features/nonvalidating/load-external-dtd")); reader.setEntityResolver(getCatalogResolver()); } else { reader.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); } } catch (Exception e) { e.printStackTrace(); } } else { try { reader.getXMLReader().setFeature("http://apache.org/xml/features/validation/schema", true); } catch (Exception e) { e.printStackTrace(); } } return reader; }
From source file:com.cladonia.xml.XMLUtilities.java
License:Open Source License
/** * Creates a new SAXReader./* w w w . j a va 2 s .c om*/ * * @param validate when true the reader validates the input. * * @return the reader. */ public static SAXReader createReader(boolean validate, boolean loadExternalDTD, boolean stripWhiteSpace) { SAXReader reader = new SAXReader(XDocumentFactory.getInstance(), validate); reader.setStripWhitespaceText(stripWhiteSpace); reader.setMergeAdjacentText(true); // reader.setMergeAdjacentText( true); if (!validate) { reader.setIncludeExternalDTDDeclarations(false); reader.setIncludeInternalDTDDeclarations(true); try { if (loadExternalDTD) { reader.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", true); // System.out.println( "http://apache.org/xml/features/nonvalidating/load-external-dtd = "+reader.getXMLReader().getFeature( "http://apache.org/xml/features/nonvalidating/load-external-dtd")); reader.setEntityResolver(getCatalogResolver()); } else { reader.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); } } catch (Exception e) { e.printStackTrace(); } } else { try { reader.getXMLReader().setFeature("http://apache.org/xml/features/validation/schema", true); } catch (Exception e) { e.printStackTrace(); } } return reader; }
From source file:edu.ku.brc.helpers.XMLHelper.java
License:Open Source License
/** * Reads a DOM from a stream// w ww . j av a 2s . co m * @param fileinputStream the stream to be read * @return the root element of the DOM */ public static org.dom4j.Element readFileToDOM4J(final FileInputStream fileinputStream) throws Exception { SAXReader saxReader = new SAXReader(); saxReader.setValidation(false); saxReader.setStripWhitespaceText(true); saxReader.setFeature("http://xml.org/sax/features/namespaces", false); saxReader.getXMLReader().setFeature("http://xml.org/sax/features/namespaces", false); //saxReader.setFeature("http://apache.org/xml/features/validation/schema", false); //saxReader.setFeature("http://xml.org/sax/features/validation", false); //saxReader.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", // (FormViewFactory.class.getResource("../form.xsd")).getPath()); org.dom4j.Document document = saxReader.read(fileinputStream); return document.getRootElement(); }
From source file:edu.ku.brc.helpers.XMLHelper.java
License:Open Source License
public static org.dom4j.Element readStrToDOM4J(final String data) throws Exception { SAXReader saxReader = new SAXReader(); saxReader.setValidation(false);/*from w w w . jav a2s . c om*/ saxReader.setStripWhitespaceText(true); saxReader.setFeature("http://xml.org/sax/features/namespaces", false); saxReader.getXMLReader().setFeature("http://xml.org/sax/features/namespaces", false); //saxReader.setFeature("http://apache.org/xml/features/validation/schema", false); //saxReader.setFeature("http://xml.org/sax/features/validation", false); //saxReader.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", // (FormViewFactory.class.getResource("../form.xsd")).getPath()); org.dom4j.Document document = saxReader.read(new StringReader(data)); return document.getRootElement(); }
From source file:edu.ku.brc.specify.toycode.L18NStringResApp.java
License:Open Source License
/** * Reads a DOM from a stream//from w w w.j a v a 2s . c om * @param fileinputStream the stream to be read * @return the root element of the DOM */ public static org.dom4j.Document readFileToDOM4J(final FileInputStream fileinputStream) throws Exception { SAXReader saxReader = new SAXReader(); saxReader.setValidation(false); saxReader.setStripWhitespaceText(true); saxReader.setFeature("http://xml.org/sax/features/namespaces", false); saxReader.getXMLReader().setFeature("http://xml.org/sax/features/namespaces", false); //saxReader.setFeature("http://apache.org/xml/features/validation/schema", false); //saxReader.setFeature("http://xml.org/sax/features/validation", false); //saxReader.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", // (FormViewFactory.class.getResource("../form.xsd")).getPath()); return saxReader.read(fileinputStream); }
From source file:es.caib.seycon.ng.servei.PuntEntradaServiceImpl.java
protected String handleValidaXMLPUE(PuntEntrada puntEntrada) throws Exception { String contingut = puntEntrada.getXmlPUE(); if (!"".equals(contingut)) { //$NON-NLS-1$ try {/*from www .j a va 2s. co m*/ // Validem el document // new // es.caib.seycon.mazinger.compiler.Compile().parse(contingut); org.dom4j.io.SAXReader reader = new org.dom4j.io.SAXReader(true); // set the validation feature to true to report validation // errors reader.setFeature("http://xml.org/sax/features/validation", true); //$NON-NLS-1$ // set the validation/schema feature to true to report // validation errors // against a schema reader.setFeature("http://apache.org/xml/features/validation/schema", true); //$NON-NLS-1$ // set the validation/schema-full-checking feature to true to // enable // full schema, grammar-constraint checking reader.setFeature("http://apache.org/xml/features/validation/schema-full-checking", //$NON-NLS-1$ true); // set the schema reader.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", //$NON-NLS-1$ "/es/caib/seycon/mazinger/Mazinger.xsd"); //$NON-NLS-1$ // set the entity resolver (to load the schema with // getResourceAsStream) reader.getXMLReader().setEntityResolver(new SchemaLoader()); reader.setEntityResolver(new SchemaLoader()); Document doc = reader.read(new ByteArrayInputStream(contingut.getBytes("UTF-8"))); //$NON-NLS-1$ } catch (Exception ex) { return ex.getMessage(); // Retornem l'excepci com error de // Validaci } } return ""; //$NON-NLS-1$ }