public Element newElement(Node parent, String name, String value) { Element element = getDocument(parent).createElement(name); parent.appendChild(element); if (value != null) element.setTextContent(value); return element; }
public Document loadDocument(InputStream input) throws IOException, SAXException { try { return getDocumentBuilderFactory().newDocumentBuilder().parse(input); } catch (ParserConfigurationException e) { throw new RuntimeException(e); } }
public Node selectSingleNode(Object context, String expression) { try { return (Node)getXPathFactory().newXPath().evaluate(expression, context, XPathConstants.NODE); } catch (Exception e) { throw new RuntimeException(e); } }
public Document newDocument(String root) { try { Document document = getDocumentBuilderFactory().newDocumentBuilder().newDocument(); document.setXmlVersion("1.0"); document.setXmlStandalone(true); if (root != null) newElement(document, root); return document; } catch (Exception e) { throw new RuntimeException(e); } }
public Document loadDocument(InputStream input, EntityResolver resolver, ErrorHandler errorHandler) throws IOException, SAXException { try { DocumentBuilder builder = getValidatingDocumentBuilderFactory().newDocumentBuilder(); builder.setEntityResolver(resolver); if (errorHandler != null) builder.setErrorHandler(errorHandler); return builder.parse(input); } catch (ParserConfigurationException e) { throw new RuntimeException(e); } }
public String toString(Document doc) { try { Transformer transformer = getTransformerFactory().newTransformer(); StringWriter writer = new StringWriter(); transformer.transform(new DOMSource(doc), new StreamResult(writer)); return writer.toString(); } catch (Exception e) { throw new RuntimeException("Could not serialize document", e); } }
public Document newDocument() { return newDocument(null); }
public Element newElement(Node parent, String name) { return newElement(parent, name, null); }
public String toNodeString(Node node) { try { Transformer transformer = getToStringTemplates().newTransformer(); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.setOutputProperty(OutputKeys.ENCODING, Charset.defaultCharset().name()); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); StringWriter sw = new StringWriter(); transformer.transform(new DOMSource(node), new StreamResult(sw)); return sw.toString(); } catch (Exception e) { throw new RuntimeException(e); } }
public String setValue(Node node, String value) { if (node != null) { String previousValue = getNormalizedValue(node); switch (node.getNodeType()) { case Node.ELEMENT_NODE: ((Element)node).setTextContent(value); break; case Node.ATTRIBUTE_NODE: case Node.TEXT_NODE: node.setNodeValue(value); break; default: throw new RuntimeException("Illegal node for write operations: " + node); } return previousValue; } return null; }
public Document newDocument(String root) { try { Document document = getDocumentBuilderFactory().newDocumentBuilder().newDocument(); document.setXmlVersion("1.0"); document.setXmlStandalone(true); if (root != null) newElement(document, root); return document; } catch (Exception e) { throw new RuntimeException(e); } }
public Document loadDocument(InputStream input, EntityResolver resolver, ErrorHandler errorHandler) throws IOException, SAXException { try { DocumentBuilder builder = getValidatingDocumentBuilderFactory().newDocumentBuilder(); builder.setEntityResolver(resolver); if (errorHandler != null) builder.setErrorHandler(errorHandler); return builder.parse(input); } catch (ParserConfigurationException e) { throw new RuntimeException(e); } }
public String toString(Document doc) { try { Transformer transformer = getTransformerFactory().newTransformer(); StringWriter writer = new StringWriter(); transformer.transform(new DOMSource(doc), new StreamResult(writer)); return writer.toString(); } catch (Exception e) { throw new RuntimeException("Could not serialize document", e); } }
public Document newDocument() { return newDocument(null); }
public Element newElement(Node parent, String name) { return newElement(parent, name, null); }
public String toNodeString(Node node) { try { Transformer transformer = getToStringTemplates().newTransformer(); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.setOutputProperty(OutputKeys.ENCODING, Charset.defaultCharset().name()); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); StringWriter sw = new StringWriter(); transformer.transform(new DOMSource(node), new StreamResult(sw)); return sw.toString(); } catch (Exception e) { throw new RuntimeException(e); } }
public String setValue(Node node, String value) { if (node != null) { String previousValue = getNormalizedValue(node); switch (node.getNodeType()) { case Node.ELEMENT_NODE: ((Element)node).setTextContent(value); break; case Node.ATTRIBUTE_NODE: case Node.TEXT_NODE: node.setNodeValue(value); break; default: throw new RuntimeException("Illegal node for write operations: " + node); } return previousValue; } return null; }
public Document newDocument(String root) { try { Document document = getDocumentBuilderFactory().newDocumentBuilder().newDocument(); document.setXmlVersion("1.0"); document.setXmlStandalone(true); if (root != null) newElement(document, root); return document; } catch (Exception e) { throw new RuntimeException(e); } }
public Node selectSingleNode(Object context, String expression) { try { return (Node)getXPathFactory().newXPath().evaluate(expression, context, XPathConstants.NODE); } catch (Exception e) { throw new RuntimeException(e); } }
public Document loadDocument(InputStream input) throws IOException, SAXException { try { return getDocumentBuilderFactory().newDocumentBuilder().parse(input); } catch (ParserConfigurationException e) { throw new RuntimeException(e); } }