0

java我今天的问题是,我很好奇在使用ksoap2-library 逐个元素解析时是否存在近亲和/或等价关系。

例如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;

我知道这可能有很多要求,但是如果可能的话,我可以在哪里获得有关此的任何信息的任何指针或提示。

4

1 回答 1

1

我认为 SAX Parser 可以帮助您。如在此链接中: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 {}

There are a lot of tutorials spread out across the internet wich show you how to use this method. The formatting in the link is quite bad, there's gotta be a better one to find.

于 2011-08-04T12:10:46.850 回答