📄 writexml.back
字号:
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.FactoryConfigurationError; import javax.xml.parsers.ParserConfigurationException; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; import java.io.File;import java.io.IOException;import java.io.*;import org.w3c.dom.Document;import org.w3c.dom.DOMException;import org.w3c.dom.Element;import org.w3c.dom.Node;import org.apache.axis.utils.XMLUtils;public class WriteXml{ Document doc; Element app; public WriteXml() { doc = XMLUtils.newDocument(); app = doc.createElement("Application"); app.setAttribute("name", "client"); app.setAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "xsi:noNamespaceSchemaLocation", "XMLConfigurator.xsd"); } public WriteXml(String schema) { doc = XMLUtils.newDocument(); app = doc.createElement("Application"); app.setAttribute("name", "client"); app.setAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "xsi:noNamespaceSchemaLocation", schema); } public Node addTopic(String name) { Node en = __addTopic(name); app.appendChild(en); return en; } public addTopic(Node father, String name) { Node en = __addTopic(name); father.appendChild(en); return en; } private Node __addTopic(String name) { Element en = doc.createElement("Topic"); en.setAttribute("name", "numStages"); return en; } public Node addParameter(Node father, String name, String name_value, String type, String value) { Node en = __addParameter(name, name_value, type, value); father.appendChild(en); return en; } public Node addParameter(String name, String name_value, String type, String value) { Node en = __addParameter(name, name_value, type, value); app.appendChild(en); return en; } private Node __addParameter(String name, String name_value, String type, String value) { Element en = doc.createElement("Parameter"); Element child_en = doc.createElement(type); Node nodeValue = doc.createTextNode(value); en.setAttribute(name, name_value); } public static void main(String args[] ) { try{ /*Document doc = XMLUtils.newDocument("try.xml"); Element en = doc.getDocumentElement(); XMLUtils.ElementToStream(en, System.out);*/ Document doc = XMLUtils.newDocument(); //Create application Element Element app = doc.createElement("Application"); app.setAttribute("name", "client"); app.setAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "xsi:noNamespaceSchemaLocation", "XMLConfigurator.xsd"); Element en = doc.createElement("Parameter"); Element child_en = doc.createElement("Integer"); Node n = doc.createTextNode("22"); en.setAttribute("name", "numStages");/* Element en = doc.createElement("Parameter"); en.setAttribute("name", "numStages");*/// Element child_en = XMLUtils.StringToElement("i", "Integer", "3");// doc.appendChild(doc.importNode(child_en, true)); en_app.appendChild(en); en.appendChild(child_en); child_en.appendChild(n); XMLUtils.PrettyElementToStream(en_app, System.out);// doc.appendChild(doc.importNode(en, true));// XMLUtils.DocumentToStream(doc, System.out); } catch(Exception e) { System.out.println(e); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -