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);
}
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));
}
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);
}
}
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();
}
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;
}
Aggregations