Search in sources :

Example 6 with DOMParser

use of org.apache.xerces.parsers.DOMParser in project nokogiri by sparklemotion.

the class NokogiriDomParser method initialize.

protected void initialize() {
    if (config == null) {
        if (xInclude) {
            config = new XIncludeParserConfiguration();
        } else {
            config = getXMLParserConfiguration();
        }
    }
    DTDConfiguration dtdConfig = new DTDConfiguration();
    dtd = new DOMParser(dtdConfig);
    config.setDTDHandler(dtdConfig);
    config.setDTDContentModelHandler(dtdConfig);
}
Also used : XIncludeParserConfiguration(org.apache.xerces.parsers.XIncludeParserConfiguration) DTDConfiguration(org.cyberneko.dtd.DTDConfiguration) DOMParser(org.apache.xerces.parsers.DOMParser)

Example 7 with DOMParser

use of org.apache.xerces.parsers.DOMParser in project wildfly by wildfly.

the class XercesUsageServlet method parse.

private void parse(final InputStream inputStream) throws IOException, SAXException {
    DOMParser domParser = new DOMParser();
    domParser.parse(new InputSource(inputStream));
}
Also used : InputSource(org.xml.sax.InputSource) DOMParser(org.apache.xerces.parsers.DOMParser)

Example 8 with DOMParser

use of org.apache.xerces.parsers.DOMParser in project ats-framework by Axway.

the class ConfigurationResource method loadFromXmlFile.

public void loadFromXmlFile(InputStream resourceStream, String resourceIdentifier) {
    try {
        DOMParser parser = new DOMParser();
        // Required settings from the DomParser
        // otherwise
        parser.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", false);
        parser.setFeature("http://apache.org/xml/features/continue-after-fatal-error", true);
        parser.setFeature("http://apache.org/xml/features/allow-java-encodings", true);
        parser.parse(new InputSource(resourceStream));
        Document doc = parser.getDocument();
        Element rootElement = doc.getDocumentElement();
        // cleanup the properties
        properties.clear();
        // init the current element path
        LinkedList<String> currentElementPath = new LinkedList<String>();
        // start reading the DOM
        NodeList rootElementChildren = rootElement.getChildNodes();
        for (int i = 0; i < rootElementChildren.getLength(); i++) {
            Node rootElementChild = rootElementChildren.item(i);
            if (rootElementChild.getNodeType() == Node.ELEMENT_NODE) {
                readXmlElement(currentElementPath, (Element) rootElementChild);
            }
        }
    } catch (SAXException e) {
        throw new ConfigurationException("Error while parsing config file '" + resourceIdentifier + "'", e);
    } catch (IOException ioe) {
        throw new ConfigurationException("Error while parsing config file '" + resourceIdentifier + "'", ioe);
    }
}
Also used : InputSource(org.xml.sax.InputSource) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) IOException(java.io.IOException) Document(org.w3c.dom.Document) LinkedList(java.util.LinkedList) SAXException(org.xml.sax.SAXException) ConfigurationException(com.axway.ats.config.exceptions.ConfigurationException) DOMParser(org.apache.xerces.parsers.DOMParser)

Example 9 with DOMParser

use of org.apache.xerces.parsers.DOMParser in project ats-framework by Axway.

the class XmlUtils method loadXML.

/**
 * Loads an XML file from a String.
 *
 * @param xmlContentsStr the source file as String
 * @return the loaded XML document
 * @throws IOException for IO error
 * @throws SAXException for parsing exception
 */
public static Document loadXML(String xmlContentsStr) throws IOException, SAXException {
    DOMParser parser = getDomParser();
    parser.parse(xmlContentsStr);
    return parser.getDocument();
}
Also used : DOMParser(org.apache.xerces.parsers.DOMParser)

Example 10 with DOMParser

use of org.apache.xerces.parsers.DOMParser in project nutch by apache.

the class DomUtil method getDom.

/**
 * Returns parsed dom tree or null if any error
 *
 * @param is XML {@link InputStream}
 * @return A parsed DOM tree from the given {@link InputStream}.
 */
public static Element getDom(InputStream is) {
    Element element = null;
    DOMParser parser = new DOMParser();
    InputSource input;
    try {
        input = new InputSource(is);
        input.setEncoding("UTF-8");
        parser.parse(input);
        int i = 0;
        while (!(parser.getDocument().getChildNodes().item(i) instanceof Element)) {
            i++;
        }
        element = (Element) parser.getDocument().getChildNodes().item(i);
    } catch (FileNotFoundException e) {
        LOG.error("Error: ", e);
    } catch (SAXException e) {
        LOG.error("Error: ", e);
    } catch (IOException e) {
        LOG.error("Error: ", e);
    }
    return element;
}
Also used : InputSource(org.xml.sax.InputSource) Element(org.w3c.dom.Element) FileNotFoundException(java.io.FileNotFoundException) DOMParser(org.apache.xerces.parsers.DOMParser) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Aggregations

DOMParser (org.apache.xerces.parsers.DOMParser)25 InputSource (org.xml.sax.InputSource)14 Node (org.w3c.dom.Node)10 Document (org.w3c.dom.Document)9 StringReader (java.io.StringReader)5 Element (org.w3c.dom.Element)5 NodeList (org.w3c.dom.NodeList)5 SAXException (org.xml.sax.SAXException)5 IOException (java.io.IOException)4 HTMLConfiguration (org.cyberneko.html.HTMLConfiguration)4 ArrayList (java.util.ArrayList)3 HtmlMaterial (fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial)2 WorkspaceMaterial (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)2 WorkspaceNode (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode)2 FileNotFoundException (java.io.FileNotFoundException)2 Transformer (javax.xml.transform.Transformer)2 XIncludeParserConfiguration (org.apache.xerces.parsers.XIncludeParserConfiguration)2 DTDConfiguration (org.cyberneko.dtd.DTDConfiguration)2 NamedNodeMap (org.w3c.dom.NamedNodeMap)2 AcsFileFinder (alma.acs.makesupport.AcsFileFinder)1