soap格式的xml解析

<?xml version="1.0"?>
<soapenv:Envelope xmlns:rxas="http://schemas.datacontract.org/2004/07/RxAssystLib.Contracts.Data" xmlns:tem="http://tempuri.org/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">   <soapenv:Header/>  
<soapenv:Body>     
<tem:User>        
<rxas:Password>Blackbox</rxas:Password>        
<rxas:UserName>jm</rxas:UserName>     
</tem:User>  
</soapenv:Body>
</soapenv:Envelope>

这种格式的xml如何在后台解析获得username 和 password的值?使用dom4j 取不到值
             次浏览         

3 个回答

--------------------------------------html

使用dom4j能够取到值, 是我有个地方写错了。
map=new HashMap();
Document xmldoc=DocumentHelper.parseText(dataxml);
Element root=xmldoc.getRootElement();
List<Element> list=root.elements();
for(int i=0; i<list.size();i++)
{
Element node=(Element)list.get(i);
List list2=node.elements();
for(int j=0; j<list2.size();j++)
{
Element element = (Element) list2.get(j);
map.put(element.getName(), element.getText());
for( Iterator iterInner = element.elementIterator(); iterInner.hasNext(); )
{
Element elementInner = (Element) iterInner.next();
map.put(elementInner.getName(), elementInner.getText());
system.out.println(elementInner.getName());
}
}
}

--------------------------------------java

很标准的一个envelope xml                                     

--------------------------------------node

我尝试解析了一下
import org.dom4j.Document;import org.dom4j.DocumentException;import org.dom4j.Element;import org.dom4j.io.SAXReader;import Java.io.File;import java.util.List;public class test{	@SuppressWarnings("unchecked")	public static void main(String[] args) throws DocumentException {		SAXReader saxReader = new SAXReader();		String path = "D:/dom.xml";		Document doc = saxReader.read(new File(path));		Element root = doc.getRootElement();		Element element = root.element("Body");		for(Element Body : (List<Element>)element.elements("User")) {			for(Element rusult_element : (List<Element>)Body.elements("Password")) {				if(rusult_element.isTextOnly()) {					System.out.println(" Password=" + rusult_element.getText());				}			}			for(Element rusult_element : (List<Element>)Body.elements("UserName")) {				if(rusult_element.isTextOnly()) {					System.out.println(" UserName=" + rusult_element.getText());				}			}		}	}}