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);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值