public void parseXMLDom()
{
String result = null;
String temp;
String dirName;
dirName = Environment.getExternalStorageDirectory()+"/download/"; // 获得存储卡路径,构成 保存文件的目标路
Log.i("start","start");
try
{
File file = null;
if(stu_code==1){
file = new File(dirName+"afariaClient.xml");
}
else if(stu_code==2){
file = new File(dirName+"afariaseed.xml");
}
if( !file.exists() )
{
Log.i("file.exists()????", file.exists()+"");
}
//构建解析器
DocumentBuilderFactory factory =DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(file);
// 开始解析
Element root = document.getDocumentElement();
temp =( "root=" + root.getTagName()+"\n" );//根节点
result += temp;
// List the children of <books>; a set of <book> elements
NodeList list = root.getChildNodes();
for( int i=0; i<list.getLength(); i++ )
{
Node node = list.item( i );
if( node.getNodeType() == Node.ELEMENT_NODE )
{
String name = node.getNodeName();
Element element = ( Element )node;
// name需要的节点
if(name.equals("seedUrl")){
xml_url = element.getTextContent();
//得到节点内容
}
else if(name.equals("afariaClientUrl")){
afaria_url = element.getTextContent();
}
else if(name.equals("ActivationCode")){
code =element.getTextContent();
Log.i("解析xml 注册码为:",code);
}
}
}
} catch( Exception e )
{
e.printStackTrace();
}
}