日期:2014-05-18  浏览次数:20720 次

使用dom4j解析xml出错
这是我的xml文件
<?xml version="1.0" encoding = "gbk"?>
<rdf:RDF xml:base="nari" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cim="http://iec.ch/TC57/2003/CIM-schema-cim10#" xmlns:cimNARI="http://www.naritech.cn/CIM/ext-schema#">
<cim:SubControlArea rdf:ID="209000001">
        <cim:Naming.name>乐平市供</cim:Naming.name>
        <cimNARI:SubControlArea.areaNo>1</cimNARI:SubControlArea.areaNo>
        <cimNARI:SubControlArea.recordApp>2031647</cimNARI:SubControlArea.recordApp>
        <cimNARI:SubControlArea.MemberOf_ControlArea rdf:resource="#209000007"/>
</cim:SubControlArea>
<cim:SubControlArea rdf:ID="209000002">
        <cim:Naming.name>德兴市</cim:Naming.name>
        <cimNARI:SubControlArea.areaNo>2</cimNARI:SubControlArea.areaNo>
        <cimNARI:SubControlArea.recordApp>2031647</cimNARI:SubControlArea.recordApp>
        <cimNARI:SubControlArea.MemberOf_ControlArea rdf:resource="#209000007"/>
</cim:SubControlArea>
<cim:SubControlArea rdf:ID="209000003">
        <cim:Naming.name>鄱阳县</cim:Naming.name>
        <cimNARI:SubControlArea.areaNo>3</cimNARI:SubControlArea.areaNo>
        <cimNARI:SubControlArea.recordApp>2031647</cimNARI:SubControlArea.recordApp>
        <cimNARI:SubControlArea.MemberOf_ControlArea rdf:resource="#209000007"/>
</cim:SubControlArea>
</rdf:RDF>

我的java代码是

import java.io.File;
import java.util.List;

import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;

public class ReadMyXML2{ 
public static void main(String[] args) throws Exception {
SAXReader saxReader = new SAXReader();
Document doc = saxReader.read(new File("work.xml"));
        Element root = doc.getRootElement();
        List<Element> lstSCA = doc.selectNodes("//*[local-name()='SubControlArea']");