List of usage examples for javax.xml.parsers DocumentBuilderFactory setValidating
public void setValidating(boolean validating)
From source file:net.sourceforge.fenixedu.util.stork.CanonicalAddressAttribute.java
private void parseAddressCompounds() { try {/*from w ww. j ava2 s . co m*/ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(false); dbf.setValidating(false); DocumentBuilder db; db = dbf.newDocumentBuilder(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( getValue().getBytes(CharEncoding.UTF_8)); Document doc = db.parse(byteArrayInputStream); setFields(doc); } catch (ParserConfigurationException e) { throw new StorkRuntimeException(e); } catch (SAXException e) { throw new StorkRuntimeException(e); } catch (IOException e) { throw new StorkRuntimeException(e); } }
From source file:com.amalto.core.save.DOMDocumentTest.java
public void testIncludeXSINamespace() throws Exception { String lineSeparator = System.getProperty("line.separator"); StringBuilder xmlBuilder = new StringBuilder( "<Organisation xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"); xmlBuilder.append(lineSeparator);/* w ww . j ava2 s . c o m*/ xmlBuilder.append("<IdOrganisation xsi:type=\"xsd:string\">5797</IdOrganisation>"); xmlBuilder.append(lineSeparator); xmlBuilder.append("</Organisation>"); xmlBuilder.append(lineSeparator); String xml = xmlBuilder.toString(); InputStream documentStream = new ByteArrayInputStream(xml.getBytes("UTF-8")); // Parsing MutableDocument userDocument; DocumentBuilderFactory DOM_PARSER_FACTORY = DocumentBuilderFactory.newInstance(); DOM_PARSER_FACTORY.setNamespaceAware(true); DOM_PARSER_FACTORY.setIgnoringComments(true); DOM_PARSER_FACTORY.setValidating(false); try { // Don't ignore talend internal attributes when parsing this document DocumentBuilder documentBuilder = new SkipAttributeDocumentBuilder( DOM_PARSER_FACTORY.newDocumentBuilder(), false); InputSource source = new InputSource(documentStream); Document userDomDocument = documentBuilder.parse(source); userDocument = new DOMDocument(userDomDocument, null, StringUtils.EMPTY, StringUtils.EMPTY); } catch (Exception e) { throw new RuntimeException("Unable to parse document to save.", e); } assertNotNull(userDocument); String result = userDocument.exportToString(); assertEquals(xml, result); }
From source file:ar.com.tadp.xml.rinzo.core.resources.validation.XMLStringValidator.java
private void saxDTDValidate(String fileName, String fileContent, DocumentStructureDeclaration structureDeclaration) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true);/*from ww w . jav a 2 s . c o m*/ factory.setValidating(true); try { DocumentBuilder builder = factory.newDocumentBuilder(); URI resolverURI = FileUtils.resolveURI(fileName, structureDeclaration.getSystemId()); if (resolverURI != null) { this.resolver.setBaseURL(fileName); this.resolver.setSystemId(structureDeclaration.getSystemId()); builder.setEntityResolver(this.resolver); } builder.setErrorHandler(this.errorHandler); builder.parse(new InputSource(new StringReader(fileContent))); } catch (Exception e) { //Do nothing because the errorHandler informs the error } }
From source file:au.csiro.casda.sodalint.ValidateCapabilities.java
/** * Validate the content of the capabilities element. * //from w w w . ja va2s. c om * @param reporter * validation message destination * @param xmlContent * The capabilities XML text * @param sodaService * The service being tested. */ void validateCapabilities(Reporter reporter, String xmlContent, SodaService sodaService) { try { DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); builderFactory.setValidating(false); builderFactory.setNamespaceAware(true); builderFactory.setFeature("http://xml.org/sax/features/validation", false); builderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); DocumentBuilder builder = builderFactory.newDocumentBuilder(); byte[] bytes = xmlContent.getBytes("UTF-8"); ByteArrayInputStream is = new ByteArrayInputStream(bytes); Document document = builder.parse(is); checkForSyncAsync(reporter, document, sodaService); } catch (ParserConfigurationException | UnsupportedEncodingException | XPathExpressionException e) { reporter.report(SodaCode.E_CPRS, "Unexpected error processing capability", e); } catch (SAXException e) { reporter.report(FixedCode.E_CPSX, "Error parsing capabilities metadata", e); } catch (IOException e) { reporter.report(FixedCode.E_CPIO, "Error reading capabilities metadata", e); } }
From source file:de.betterform.xml.dom.DOMUtil.java
private static DocumentBuilder createDocumentBuilder(boolean namespaces, boolean validating) throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(namespaces); factory.setValidating(validating); // factory.setAttribute("http://xml.org/sax/features/namespace-prefixes)",new Boolean(true)); DocumentBuilder builder = factory.newDocumentBuilder(); return builder; }
From source file:de.uzk.hki.da.metadata.XsltGenerator.java
/** * @return/*from w w w. java 2 s . c o m*/ * @throws TransformerException * @throws IOException */ public String generate() throws TransformerException, IOException { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating(false); dbf.setNamespaceAware(true); try { dbf.setFeature("http://xml.org/sax/features/namespaces", false); dbf.setFeature("http://xml.org/sax/features/validation", false); dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); } catch (ParserConfigurationException e2) { throw new RuntimeException(e2); } DocumentBuilder parser; Document doc = null; try { parser = dbf.newDocumentBuilder(); doc = parser.parse(inputStream); } catch (Exception e) { throw new RuntimeException(e); } Source xmlSource = new DOMSource(doc); for (String key : params.keySet()) { transformer.setParameter(key, params.get(key)); } ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); transformer.transform(xmlSource, new StreamResult(outputStream)); try { return outputStream.toString("UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } finally { inputStream.close(); outputStream.close(); } }
From source file:net.mumie.coursecreator.xml.ELClassListWrapper.java
private ELClassListWrapper() throws ParserConfigurationException { DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance(); fac.setIgnoringComments(true);//from w w w .ja v a 2 s.c o m fac.setNamespaceAware(true); fac.setValidating(false); this.domBuilder = fac.newDocumentBuilder(); }
From source file:de.betterform.xml.dom.DOMUtil.java
public static Node getFragment(URI uri, InputStream xmlStream) throws XFormsException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true);/*from w w w.j a v a 2 s. co m*/ factory.setValidating(false); Document document = null; try { document = parseInputStream(xmlStream, true, false); } catch (ParserConfigurationException e) { throw new XFormsException(e); } catch (SAXException e) { throw new XFormsException(e); } catch (IOException e) { throw new XFormsException(e); } if (uri.getFragment() != null) { String fragment = uri.getFragment(); if (fragment.indexOf("?") != -1) { fragment = fragment.substring(0, fragment.indexOf("?")); } return getById(document, fragment); } return document; }
From source file:com.bdaum.juploadr.uploadapi.locrrest.upload.LocrUpload.java
public LocrUpload(ImageAttributes img, Session session, UploadStatusMonitor monitor) { super(session); this.image = img; this.monitor = monitor; handler = new LocrUploadResponseHandler(this); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); factory.setNamespaceAware(false);/*from ww w . j ava 2 s.c om*/ }
From source file:com.flexive.faces.beans.PluginRegistryBean.java
/** * Return the XML document represented by the given URL. * * @param configFile the config file URL * @return the XML document represented by the given URL. * @throws ParserConfigurationException if the parser could not be instantiated * @throws SAXException if the document could not be parsed * @throws IOException if the file could not be read *//*www. j a v a2s . c o m*/ private Document getXmlDocument(URL configFile) throws ParserConfigurationException, SAXException, IOException { final DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); builderFactory.setValidating(false); final DocumentBuilder builder = builderFactory.newDocumentBuilder(); return builder.parse(configFile.openStream()); }