标题:Properties类读取xml文件老出错,提示DTD文件有问题.请问该怎么弄
取消只看楼主
rossi789
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2005-8-13
 问题点数:0 回复次数:2 
Properties类读取xml文件老出错,提示DTD文件有问题.请问该怎么弄

这是xml文件

<?xml version="1.0" encoding="gbk"?>
<!DOCTYPE persons SYSTEM "person.dtd">

<persons>
<person name="jiang">
<age>11</age>
<email>element@hz.cn</email>
</person>

<person name="hong">
<age>22</age>
<email>rossi789@163.com</email>
</person>

<person name="bing">
<age>33</age>
<email>jianghb.jesse@yahoo.com.cn</email>
</person>

</persons>


这是DTD文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE persons [
<!ELEMENT persons (person*)>
<!ELEMENT person (age, email)>
<!ALLLIST person name CDATA "null">
<!ELEMENT age (#PCDATA)>
<!ELEMENT email (#PCDATA)>
]>

这是程序代码

/**
* @project jiangHB_j2se
* @file_name ReadCfg.java
*/

package ch0;

import java.util.*;
import java.io.*;

/**
* @author jhb
* @version 1.0
* @create_on Sep 23, 2007 3:17:35 PM
*/
public final class ReadCfg {

public static void main(String[] args) {
Properties file = new Properties();
try {
file.loadFromXML(new FileInputStream("gateway.xml"));
file.list(System.out);
} catch (IOException e) {
e.printStackTrace();
}
}

}

搜索更多相关主题的帖子: xml文件 DTD Properties person 
2007-09-23 16:45
rossi789
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2005-8-13
得分:0 
回复:(rossi789)Properties类读取xml文件老出错,提...
这是错误提示,请问到底要怎么搞才能读取?
java.util.InvalidPropertiesFormatException: org.xml.sax.SAXException: Invalid system identifier: file:///D:/MyJavaProject/jiangHB_j2se/person.dtd
at java.util.XMLUtils.load(XMLUtils.java:59)
at java.util.Properties.loadFromXML(Properties.java:701)
at ch0.ReadCfg.main(ReadCfg.java:21)
Caused by: org.xml.sax.SAXException: Invalid system identifier: file:///D:/MyJavaProject/jiangHB_j2se/person.dtd
at java.util.XMLUtils$Resolver.resolveEntity(XMLUtils.java:174)
at com.sun.org.apache.xerces.internal.util.EntityResolverWrapper.resolveEntity(EntityResolverWrapper.java:148)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.resolveEntity(XMLEntityManager.java:701)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(XMLDocumentScannerImpl.java:1019)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:368)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:250)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:292)
at java.util.XMLUtils.getLoadingDoc(XMLUtils.java:85)
at java.util.XMLUtils.load(XMLUtils.java:57)
... 2 more
2007-09-23 16:48
rossi789
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2005-8-13
得分:0 

dom太麻烦了,要弄好几个Element,Document,NodeList对象.
Properties用get方法就可以直接取到的

2007-09-23 18:42



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-172319-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.830449 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved