<Messages>
<Message>
<CONTENT>
<Map>
<Item>
<Key>MessageID</Key><Value>a0f630e0-aeec-11e2-b248-0000c0a8016e</Value>
</Item>
<Item><Key>ApplicationID</Key><Value>MH</Value></Item>
<Item><Key>CreatedTime</Key><Value>2013-04-27 :43:31.054</Value></Item>
<Item>
<Key>DATA</Key>
<Value>
<Item><Key>name</Key><Value>indexNum</Value></Item>
<Item><Key>jgdm</Key><Value>0105</Value></Item>
</Value>
</Item>
</Map>
</CONTENT>
<TAIL/>
</Message>
</Messages>
我想根据name获取值,也就是说根据name获取到indexNum的值,怎么获取啊,谢谢了 JavaXML节点值

解决方案 »

  1.   

    <Value>
    <Item>
    <Key>name</Key>
    <Value>indexNum</Value>
    </Item>
    <Item>
    <Key>jgdm</Key>
    <Value>0105</Value>
    </Item>
    </Value>
    是这一段吗,通过name获取indexNum,通过jgdm获取0105?
      

  2.   


    这段代码我拷了三遍了
    /**
         * 读取xml文件
         * @param fileName
         */ 
        void parserXml(String fileName)  
        {    
            File inputXml=new File(fileName);    
            SAXReader saxReader = new SAXReader();    
            try {    
                Document document = saxReader.read(inputXml);   //把文件读入到文档 
                Element barcodeInfo=document.getRootElement();   //获取文档根节点 
                this.doublexml(barcodeInfo); 
                    
            } catch (DocumentException e) {    
                System.out.println(e.getMessage());    
            }    
        }    
         
         
        private void doublexml(Element ele) 
        { 
         StringBuilder sb = new StringBuilder();
        
            for(Iterator i = ele.elementIterator();i.hasNext();) 
            { 
                Element node = (Element)i.next(); 
                System.out.println("节点名:"+node.getName()); 
                String nodeName = node.getName();
                if(node.attributes()!=null && node.attributes().size()>0) 
                { 
                    for(Iterator j = node.attributeIterator();j.hasNext();) 
                    { 
                        Attribute item = (Attribute)j.next(); 
                        System.out.print("属性名:"+item.getName()+"\t属性值:"+item.getValue()+"\n"); 
                    } 
                } 
                if(node.getText().length()>0) 
                { 
                    System.out.println("节点值:"+node.getText()); 
                    String nodeText = node.getText();
                } 
                if(node.elementIterator().hasNext()) 
                { 
                    this.doublexml(node); 
                } 
            }
        } 
      

  3.   

    是在看不出来key和value有什么关系,为什么不直接取出value值呢。