2012-09-17 1 views
0
나는 다음의 InputStream에서 "의 SearchResult"값을 얻으려면

: 나는이 DOM 파서를 사용하려고 노력했지만 문제가 있어요, 그리고 확실하지 않다SOAP 응답에서 단일 요소의 값을 얻는 방법은 무엇입니까? (자바)

HTTP/1.1 200 OK 
Content-Type: application/soap+xml; charset=utf-8 
Content-Length: length 

<?xml version="1.0" encoding="utf-8"?> 
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> 
    <soap12:Body> 
     <SearchResponse xmlns="[url here]"> 
      <SearchResult>[THIS VALUE HERE]</SearchResult> 
     </SearchResponse> 
     </soap12:Body> 
</soap12:Envelope> 

는 권리 인 경우 접근 방식 :

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 
DocumentBuilder db; 
Document doc = null; 

db = factory.newDocumentBuilder(); 
InputSource inStream = new InputSource(); 
inStream.setCharacterStream(new StringReader(soapResponse)); 
doc = db.parse(inStream); 

NodeList nl = doc.getElementsByTagName("SearchResult"); 
//Not sure how to get the value... Everything I've tried returned "null". Help? 

어떻게하면됩니까?

자바와 안드로이드 레벨 8 이상 들어

답변

1

: nodeList.item(0).getTextContent()

안드로이드 레벨 1 및 최신 경우 : 그 나에게 오류를 제공하기 때문에 nodeList.item(0).getFirstChild().getNodeValue()

+0

내가하지 않은 "전화는 API 레벨 8을 필요로 (현재 분은 7입니다.) ... " – Kalina

+1

흠 ... Java 6에서 저에게 도움이됩니다.하지만 Android 태그를 추가 한 것을 볼 수 있습니다. 이제 안드로이드는 Java가 아닙니다. (Android! = Java). 이것은 귀하의 타겟 안드로이드 버전에 문제가 있습니다 ... 당신은 안드로이드 2.1.x 호환해야합니까? –

+1

api 수준 1 android에서 작동하는 대답으로 업데이트되었습니다. –

관련 문제