ksoap2 相当于 didStart/didEndElement?

发布于 2024-11-28 01:08:48 字数 864 浏览 1 评论 0原文

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

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;

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅浅 2024-12-05 01:08:48

我认为 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 {}

互联网上有很多教程向您展示如何使用此方法。链接中的格式非常糟糕,必须找到更好的格式。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文