首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

为啥dom保存的时候把dtd给漏了

2012-08-14 
为什么dom保存的时候把dtd给漏了?保存前?xml version1.0 encodingUTF-8?!DOCTYPE othersetPUBLIC

为什么dom保存的时候把dtd给漏了?
保存前
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE otherset PUBLIC "hengsheng" "OtherSet.dtd">
<otherset>
程序配置设置
<setprogram>
<userpswd>
<username>nbcx</username>
<password>nbcxyey</password>
</userpswd>
</setprogram>
</otherset>
程序代码
 DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
DocumentBuilder db=dbf.newDocumentBuilder();
Document doc= db.parse(new File("OtherSet.xml"));  
Element eltupd= (Element) doc.getElementsByTagName("userpswd").item(0);
Node nduser=eltupd.getElementsByTagName("username").item(0);
nduser.getFirstChild().setNodeValue(text.getText());  
TransformerFactory tff=TransformerFactory.newInstance();
Transformer tf=tff.newTransformer();
tf.setOutputProperty("encoding","UTF-8");
DOMSource source=new DOMSource(doc);
StreamResult result=new StreamResult(new File("OtherSet.xml"));
tf.transform(source,result);
结果修改后进行保存,xml中
<!DOCTYPE otherset PUBLIC "hengsheng" "OtherSet.dtd">这一句就没有了.

[解决办法]
我知道了,使用dom是不行的,必须换jdom或dom4j

热点排行