2011-08-04 2 views
0

오늘 내 질문에 대해서는 가까운 상대 및/또는 동등한 경우 javaksoap2- 라이브러리를 사용하여 요소별로 구문 분석 할 수 있는지 궁금합니다.kostap2는 didStart/didEndElement와 동일합니까?

예를 들어 objective-c에서 :

public void didEndElement(args....){ 

    if occurring element is thisElement 
    //do something with the value in the element 


} 

public void didStartElement(args....){ 

    if occurring element is thisElement 
    //do something with the value in the element 


} 

동안 java

SoapObject foo = (SoapObject)bar.getProperty(enum); 

aString = foo.getProperty(enum); 

aNotherString = foo.getProperty(anotherEnum); 
이 그래서, 기본적으로, 우리가하고 싶은 것은

에서

즉석 java 구문 :

if(currentElement == "myElement") 
aVar = valueInElement; 
// or 
a[1] = valueInElement; 

나는이 점에 대해 많은 것을 알고 있을지도 모른다. 그러나 이것에 대한 정보를 어디에서 얻을 수 있는지에 대한 모든 조언이나 힌트는 전혀 없다.

답변

1

SAX 파서가 도움을 줄 수 있다고 생각합니다. 이 링크의 내용 : http://www.androidpeople.com/android-xml-parsing-tutorial-using-saxparser

MyXmlHandler라는 클래스가 만들어집니다. 이 클래스는 DefaultHandler 클래스를 확장하여 startElement 및 endElement 메소드를 재정의 할 수있게합니다.

@Override 
public void startElement(String uri, String localName, String qName, 
Attributes attributes) throws SAXException {} 

@Override 
public void endElement(String uri, String localName, String qName) 
throws SAXException {} 

@Override 
public void characters(char[] ch, int start, int length) 
throws SAXException {} 

이 방법을 사용하는 방법을 보여주는 인터넷을 통해 많은 자습서가 나와 있습니다. 링크의 형식은 상당히 나쁩니다. 더 나은 형식을 찾아야합니다.

+0

이 링크는 더 좋은 예일 수 있습니다. http://www.jondev.net/articles/Android_XML_SAX_Parser_Example – Bart

+0

다른 종류의 솔루션으로이 문제를 해결했지만 성공한 대답이 유일한 답변 이었으므로, 올바른 것으로 표시하겠습니다. 응답 해 주셔서 감사합니다. – doge