XmlPullParser parser;
String Version = parser.getAttributeValue(0);
String COMPANY= parser.getAttributeValue(1);

解决方案 »

  1.   

    建议参考一下以下代码! 
          InputStream in=this.getResources().getAssets().open("test.xml")
        public void CXmlTests(InputStream in)
        {
            LoadXmlTask loadTask=new LoadXmlTask();
            boolean result=true;
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            try 
            {
                DocumentBuilder builder = factory.newDocumentBuilder();
                Document dom = builder.parse(in);
                Element root = dom.getDocumentElement();        
                NodeList items = root.getElementsByTagName("Layout");//查找所有person节点
                if(items==null) return;
                //取Layout节点
                Node LayoutNode = items.item(0);    
                NamedNodeMap nMap=LayoutNode.getAttributes();//取Layout属性
                if(nMap!=null)
                {
                    for(int j=0;j<nMap.getLength();j++)
                       System.out.println(nMap.item(j).getNodeName()+" "+nMap.item(j).getNodeValue());
                }
                /*取Layout内所有节点*/
                NodeList nodeList=LayoutNode.getChildNodes();
                for(int j=0;j<nodeList.getLength();j++)
                {
                    Node sNode=nodeList.item(j);
                    //这里处理 ConA ConB ConC 节点                
                    System.out.println(sNode.getNodeName());
                }            
            }
            catch(Exception e)
            {
                System.out.println(e.getMessage());
            }        
        }   
      

  2.   

    import java.util.ArrayList;
    import java.util.List;import org.xml.sax.Attributes;
    import org.xml.sax.SAXException;
    import org.xml.sax.helpers.DefaultHandler;import cn.xml.domain.Person;public class XMLContentHandler extends DefaultHandler {
    private List<Person> persons = null;
    private Person currentPerson;
    private String tagName = null;//当前解析的元素标签 public List<Person> getPersons() {
    return persons;
    }
    /*
     * 接收文档的开始的通知。
     */
    @Override public void startDocument() throws SAXException {
    persons = new ArrayList<Person>();
    }
    /*
     * 接收字符数据的通知。
     */
    @Override public void characters(char[] ch, int start, int length) throws SAXException {
    if(tagName!=null){
    String data = new String(ch, start, length);
    if(tagName.equals("name")){
    this.currentPerson.setName(data);
    }else if(tagName.equals("age")){
    this.currentPerson.setAge(Short.parseShort(data));
    }
    }
    }
    /*
     * 接收元素开始的通知。
     * 参数意义如下:
     *    namespaceURI:元素的命名空间
     *    localName :元素的本地名称(不带前缀)
     *    qName :元素的限定名(带前缀)
     *    atts :元素的属性集合
     */
    @Override public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
    if(localName.equals("person")){
    currentPerson = new Person();
    currentPerson.setId(Integer.parseInt(atts.getValue("id")));
    }
    this.tagName = localName;
    }
    /*
     * 接收文档的结尾的通知。
     * 参数意义如下:
     *    uri :元素的命名空间
     *    localName :元素的本地名称(不带前缀)
     *    name :元素的限定名(带前缀)
     * 
     */
    @Override public void endElement(String uri, String localName, String name) throws SAXException {
    if(localName.equals("person")){
    persons.add(currentPerson);
    currentPerson = null;
    }
    this.tagName = null;
    }
    }
      

  3.   

    我说了用XmlPullParser解析,还考被个别的代码啊。自己解决了
      

  4.   

    怎么解决的呀 我现在也要用XmlPullParser判断子节点是否存在 教教我呀