头大了:求解决! 运行main方法,报如下错误

老悍匪 发布于 2014/03/14 13:53
阅读 1K+
收藏 0

org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 6; 与元素类型 "null" 相关联的 "name" 属性值不能包含 '<' 字符。 

at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)

at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLScanner.scanAttributeValue(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanAttribute(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(Unknown Source)
at com.pythagorastech.tms.ui.util.LocationLoader.getLocation(LocationLoader.java:35)

at com.pythagorastech.tms.ui.util.LocationLoader.main(LocationLoader.java:82)




帮忙看看这是为什么



xml如下:

<?xml version="1.0" encoding="utf-8"?>
<location>
<province id='1' name='北京市'>
    <city id='1' name='北京市'>
        <district id='1' name='东城区'/>
        <district id='2' name='西城区'/>
        <district id='3' name='崇文区'/>
        <district id='4' name='宣武区'/>
        <district id='5' name='朝阳区'/>
        <district id='6' name='丰台区'/>
        <district id='7' name='石景山区'/>
        <district id='8' name='海淀区'/>
        <district id='9' name='门头沟区'/>
        <district id='10' name='房山区'/>
        <district id='11' name='通州区'/>
        <district id='12' name='顺义区'/>
        <district id='13' name='昌平区'/>
        <district id='14' name='大兴区'/>
        <district id='15' name='怀柔区'/>
        <district id='16' name='平谷区'/>
        <district id='17' name='密云县'/>
        <district id='18' name='延庆县'/>
    </city>
</province>
</location>


我的代码如下:

public class LocationLoader extends DefaultHandler {
private Map<String, Map<String, List<String>>> location = new LinkedHashMap<>();
private Map<String, List<String>> provinceMap;
private List<String> cityList;
private String province;
private String city;
private String district;


private String tag = null;


public final Map<String, Map<String, List<String>>> getLocation() {
try {
SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
InputStream is = Runtime.class.getResourceAsStream("/com/pythagorastech/tms/ui/res/xml/location.xml");
parser.parse(new InputSource(new BufferedReader(
new InputStreamReader(is))), this);
} catch (IOException | ParserConfigurationException | SAXException e) {
e.printStackTrace();
}
return location;
}



public static void main(String[] args) throws ParserConfigurationException,
SAXException, IOException {

LocationLoader handler = new LocationLoader();

System.out.println(handler.getLocation());
}
}

加载中
0
alexgaoyh
alexgaoyh

建议先看一下这个链接:

http://www.ibm.com/developerworks/cn/xml/x-saxhandle/index.html



返回顶部
顶部