List of usage examples for org.w3c.dom DOMImplementation createDocument
public Document createDocument(String namespaceURI, String qualifiedName, DocumentType doctype) throws DOMException;
From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); DOMImplementation impl = builder.getDOMImplementation(); Document doc = impl.createDocument(null, null, null); Element e1 = doc.createElement("api"); doc.appendChild(e1);/*from w ww. j a v a2 s .co m*/ Element e2 = doc.createElement("java"); e1.appendChild(e2); e2.setAttribute("url", "http://www.domain.com"); DOMSource domSource = new DOMSource(doc); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); StringWriter sw = new StringWriter(); StreamResult sr = new StreamResult(sw); transformer.transform(domSource, sr); System.out.println(sw.toString()); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); DOMImplementation impl = builder.getDOMImplementation(); Document doc = impl.createDocument(null, null, null); Element e1 = doc.createElement("api"); doc.appendChild(e1);// w ww .j av a2 s.c om Element e2 = doc.createElement("java"); e1.appendChild(e2); e2.setAttribute("url", "http://www.java2s.com"); //transform the DOM for showing the result in console DOMSource domSource = new DOMSource(doc); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); StringWriter sw = new StringWriter(); StreamResult sr = new StreamResult(sw); transformer.transform(domSource, sr); System.out.println(sw.toString()); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); DOMImplementation impl = builder.getDOMImplementation(); Document doc = impl.createDocument(null, null, null); Element e1 = doc.createElement("api"); doc.appendChild(e1);/* w w w . j a va 2s . c o m*/ Element e2 = doc.createElement("java"); e1.appendChild(e2); e2.setAttribute("url", "http://www.java2s.com"); // transform the DOM for showing the result in console DOMSource domSource = new DOMSource(doc); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); StringWriter sw = new StringWriter(); StreamResult sr = new StreamResult(sw); transformer.transform(domSource, sr); System.out.println(sw.toString()); }
From source file:SVGGraphics2DDemo.java
public static void main(String args[]) throws IOException { SVGGraphics2DDemo sv2Demo = new SVGGraphics2DDemo(); DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation(); Document doc = domImpl.createDocument(null, "svg", null); SVGGraphics2D svg = new SVGGraphics2D(doc); sv2Demo.paint(svg);/*from w ww . j av a2s. c o m*/ svg.stream(new FileWriter("booktitle.svg"), false); }
From source file:Main.java
public static void main(String args[]) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); DOMImplementation impl = builder.getDOMImplementation(); Document xmldoc = impl.createDocument(null, "XMLDoc", null); Element root = xmldoc.getDocumentElement(); Element e0 = xmldoc.createElement("Doc"); Element e1 = xmldoc.createElement("TITLE"); Node n1 = xmldoc.createTextNode("Java"); e1.appendChild(n1);/*from w ww. ja va 2 s . c o m*/ Element e2 = xmldoc.createElement("data"); Node n2 = xmldoc.createTextNode("text node"); e2.appendChild(n2); e0.appendChild(e1); e0.appendChild(e2); root.appendChild(e0); StreamResult out = new StreamResult("howto.xml"); DOMSource domSource = new DOMSource(xmldoc); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.transform(domSource, out); }
From source file:Main.java
public static void main(String args[]) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); DOMImplementation impl = builder.getDOMImplementation(); Document xmldoc = impl.createDocument(null, "TODOs", null); Element root = xmldoc.getDocumentElement(); Element e0 = xmldoc.createElement("TOPIC"); Element e1 = xmldoc.createElement("TITLE"); Node n1 = xmldoc.createTextNode("Java"); e1.appendChild(n1);/*from w ww . jav a2 s.co m*/ Element e2 = xmldoc.createElement("URL"); Node n2 = xmldoc.createTextNode("http://www.server.com"); e2.appendChild(n2); e0.appendChild(e1); e0.appendChild(e2); root.appendChild(e0); Node pi = xmldoc.createProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\"TODOs.xsl\""); xmldoc.insertBefore(pi, root); StreamResult out = new StreamResult("howto.xml"); DOMSource domSource = new DOMSource(xmldoc); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.transform(domSource, out); }
From source file:Main.java
public static Document emptyDocument(String title) { DOMImplementation impl = getDOMImpl(); Document doc = impl.createDocument("urn:hl7-org:v2xml", title, null); return doc;//from w w w .j a va 2 s . co m }
From source file:Main.java
public static Document createDocument(String iName) throws ParserConfigurationException { DocumentBuilderFactory lFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder lBuilder = lFactory.newDocumentBuilder(); DOMImplementation lBuilderImpl = lBuilder.getDOMImplementation(); return lBuilderImpl.createDocument(null, iName, null); }
From source file:Main.java
/** Creates a new XML document. * * @param namespace the default namespace of the document * @param documentElement the name of the document element * @return a new XML document//w w w .j a v a 2 s.co m */ public static Document createDocument(String namespace, String documentElement) { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); DOMImplementation impl = builder.getDOMImplementation(); return impl.createDocument(namespace, documentElement, null); } catch (ParserConfigurationException e) { // This exception is never thrown, treat as fatal if it is throw new RuntimeException(e); } }
From source file:Main.java
public static Document getXMLDoc(String root) throws ParserConfigurationException { Document xmldoc = null;/* w w w.ja v a 2 s . c o m*/ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); DOMImplementation impl = builder.getDOMImplementation(); // Document. xmldoc = impl.createDocument(null, root, null); return xmldoc; }