0

my question for today is that i'm curious about if there is a close relative and/or equivalence in java using the ksoap2-library to parse element-by-elements.

In objective-c for example:

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


}

While in java

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

aString = foo.getProperty(enum);

aNotherString = foo.getProperty(anotherEnum);

So, basically, what we want to do is,

improvised java syntax:

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

I know that this might a be a lot to ask for, but any pointers or hints to where i can attain any information about this, if it is possible at all.

Jens Bergvall
  • 1,617
  • 2
  • 24
  • 54

1 Answers1

1

I think the SAX Parser can help you with that. As in this link: http://www.androidpeople.com/android-xml-parsing-tutorial-using-saxparser

There, a class named MyXmlHandler is created. This one extends the DefaultHandler class and allows you to override the startElement and endElement methods.

@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.

Bart
  • 363
  • 1
  • 3
  • 11
  • On second tought, this link might be a better example: http://www.jondev.net/articles/Android_XML_SAX_Parser_Example – Bart Aug 04 '11 at 12:12
  • We succeeded solving this with another kind of solution, but since your answer was the only answer, i'll mark it as correct. Thanks for the response. – Jens Bergvall Aug 08 '11 at 06:19