H
huchuandong
Unregistered / Unconfirmed
GUEST, unregistred user!
xml文件格式:
<?xml version="1.0"
encoding="GB2312"?>
<setup>
<ope id="1">
<tname>pcs_zuzhi</tname>
</ope>
<ope id="2">
<tname>pcs_zhian</tname>
</ope>
</setup>
请问高人:我在程序传一参数pid,如何获取id=pid中tname的内容,我是这样写的,但报错:
publicdo
cument loadXml() throws Exception{
Documentdo
c=null;
SAXReader reader=new SAXReader();
try{
doc=reader.read(new File(file));
}
catch (Exception ex){
ex.printStackTrace();
System.out.println("XmlReader中loadXml出错!"
throw(ex);
}
returndo
c;
}
/*
* 读xml文件
*/
public Vector readXml(String id){
Vector vec=new Vector();
Documentdo
c=null;
try{
doc=loadXml();
doc.getRootElement();
Node node=(Node)doc.selectSingleNode("//setup/opeid[@id='"+id+"']"
System.out.println("test"+node.valueOf("tname");
}
catch (Exception ex){
ex.printStackTrace();
System.out.println("XmlReader中readXml出错!"
}
}
<?xml version="1.0"
encoding="GB2312"?>
<setup>
<ope id="1">
<tname>pcs_zuzhi</tname>
</ope>
<ope id="2">
<tname>pcs_zhian</tname>
</ope>
</setup>
请问高人:我在程序传一参数pid,如何获取id=pid中tname的内容,我是这样写的,但报错:
publicdo
cument loadXml() throws Exception{
Documentdo
c=null;
SAXReader reader=new SAXReader();
try{
doc=reader.read(new File(file));
}
catch (Exception ex){
ex.printStackTrace();
System.out.println("XmlReader中loadXml出错!"
throw(ex);
}
returndo
c;
}
/*
* 读xml文件
*/
public Vector readXml(String id){
Vector vec=new Vector();
Documentdo
c=null;
try{
doc=loadXml();
doc.getRootElement();
Node node=(Node)doc.selectSingleNode("//setup/opeid[@id='"+id+"']"
System.out.println("test"+node.valueOf("tname");
}
catch (Exception ex){
ex.printStackTrace();
System.out.println("XmlReader中readXml出错!"
}
}