List of usage examples for javax.xml.parsers DocumentBuilderFactory newDocumentBuilder
public abstract DocumentBuilder newDocumentBuilder() throws ParserConfigurationException;
From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true);/*from w w w .j a va 2 s. c o m*/ factory.setExpandEntityReferences(false); Document doc = factory.newDocumentBuilder().parse(new File("filename")); Source source = new DOMSource(doc); URI uri = new File("infilename.xml").toURI(); source.setSystemId(uri.toString()); DefaultHandler handler = new MyHandler(); SAXResult result = new SAXResult(handler); Transformer xformer = TransformerFactory.newInstance().newTransformer(); xformer.transform(source, result); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true);// ww w .j a v a2s . co m factory.setExpandEntityReferences(false); Document doc = factory.newDocumentBuilder().parse(new File("filename")); Element element = doc.getElementById("key1"); CDATASection cdataNode = doc.createCDATASection(""); Comment commentNode = doc.createComment(""); Text textNode = doc.createTextNode(""); // All three types of nodes implement the CharacterData interface CharacterData cdata = cdataNode; cdata = commentNode; cdata = textNode; // Delete text int offset = 0; int len = 5; cdata.deleteData(offset, len); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true);/*from w ww . j a v a 2s. c om*/ factory.setExpandEntityReferences(false); Document doc = factory.newDocumentBuilder().parse(new File("filename")); Element element = doc.getElementById("key1"); CDATASection cdataNode = doc.createCDATASection(""); Comment commentNode = doc.createComment(""); Text textNode = doc.createTextNode(""); // All three types of nodes implement the CharacterData interface CharacterData cdata = cdataNode; cdata = commentNode; cdata = textNode; cdata.setData("some data"); int len = cdata.getLength(); int offset = 5; len = 4; String s = cdata.substringData(offset, len); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true);//from w w w.ja v a 2s. c om factory.setExpandEntityReferences(false); Document doc = factory.newDocumentBuilder().parse(new File("filename")); Element element = doc.getElementById("key1"); CDATASection cdataNode = doc.createCDATASection(""); Comment commentNode = doc.createComment(""); Text textNode = doc.createTextNode(""); // All three types of nodes implement the CharacterData interface CharacterData cdata = cdataNode; cdata = commentNode; cdata = textNode; // data int offset = 5; cdata.insertData(offset, "a "); cdata.appendData(" b"); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true);/*ww w . j av a2 s . com*/ factory.setExpandEntityReferences(false); Document doc = factory.newDocumentBuilder().parse(new File("filename")); Element element = doc.getElementById("key1"); CDATASection cdataNode = doc.createCDATASection(""); Comment commentNode = doc.createComment(""); Text textNode = doc.createTextNode(""); // All three types of nodes implement the CharacterData interface CharacterData cdata = cdataNode; cdata = commentNode; cdata = textNode; // Replace text String replacement = "c"; int offset = 10; int len = 6; cdata.replaceData(offset, len, replacement); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(xmlRecords)); Document doc = factory.newDocumentBuilder().parse(is); CDATASection cdataNode = doc.createCDATASection(""); CharacterData cdata = cdataNode; cdata.appendData("from java2s.com"); System.out.println(cdataNode.getLength()); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(xmlRecords)); Document doc = factory.newDocumentBuilder().parse(is); CDATASection cdataNode = doc.createCDATASection(""); CharacterData cdata = cdataNode; cdata.setData("from java2s.com"); System.out.println(cdataNode.substringData(2, 4)); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(xmlRecords)); Document doc = factory.newDocumentBuilder().parse(is); CDATASection cdataNode = doc.createCDATASection(""); CharacterData cdata = cdataNode; cdata.setData("from java2s.com"); System.out.println(cdataNode); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(xmlRecords)); Document doc = factory.newDocumentBuilder().parse(is); CDATASection cdataNode = doc.createCDATASection(""); CharacterData cdata = cdataNode; cdata.appendData("from java2s.com"); cdata.deleteData(1, 2);/* w w w .j a v a 2 s . c o m*/ System.out.println(cdataNode); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(xmlRecords)); Document doc = factory.newDocumentBuilder().parse(is); CDATASection cdataNode = doc.createCDATASection(""); CharacterData cdata = cdataNode; cdata.appendData("from java2s.com"); cdata.deleteData(1, 2);/* ww w . ja va 2 s .co m*/ System.out.println(cdataNode.getData()); }