java xml setdoctype_如何在Java中使用DOM将自定义doctype标记添加到带有xhtml标记的xml中?...
我使用java中的DOM創建了一個XML文檔,并將XHTML標記插入到XML文檔中。現在我要添加如下doctype:
]>
我試著把它作為一個字符串追加,但沒有成功。
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
docFactory.setNamespaceAware(true);
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
DOMImplementation domImpl = docBuilder.getDOMImplementation();
Document xmlDoc = domImpl.createDocument(null, "example", null);
xmlDoc.setXmlVersion("1.0");
xmlDoc.setXmlStandalone(true);
String xhtmlTag = "xhtml tags";
ByteArrayInputStream bis = new ByteArrayInputStream(xml.getBytes());
Document doc2 = docBuilder.parse(bis);
Node xhtml = xmlDoc.importNode(doc2.getDocumentElement(), true);
ProcessingInstruction pi = xmlDoc.createProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\"#stylesheet\"");
Element example = xmlDoc.getDocumentElement();
beyanname.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
example.setAttribute("xsi:noNamespaceSchemaLocation", "TEST.xsd");
example.setAttribute("lang", "az");
example.setAttribute("error", "xeta_yoxdur");
xmlDoc.insertBefore(pi, example);
example.appendChild(xhtml);
總結
以上是生活随笔為你收集整理的java xml setdoctype_如何在Java中使用DOM将自定义doctype标记添加到带有xhtml标记的xml中?...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql 获取天数_MySQL获取某月
- 下一篇: 策略 python_Python版商品期