在android中使用SAX解析属性

发布于 2025-01-08 04:15:52 字数 308 浏览 2 评论 0原文

是否可以使用 SAX 解析器解析 xml 文件中的属性?

例如:我能够轻松解析:

<author>Hina2</author>

结果:Hina2

如何解析以下属性:

<text author="Hina2" timeModified="timestampgoeshere" 
pos="pre" priority="0" thumbUrl="text2" url="textfull2"/>

谢谢!

Is it possible to parse attributes from an xml file using SAX parser?

ex: I am able to easily parse:

<author>Hina2</author>

Result: Hina2

How do I parse the attributes from:

<text author="Hina2" timeModified="timestampgoeshere" 
pos="pre" priority="0" thumbUrl="text2" url="textfull2"/>

Thanks!

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

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

发布评论

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

评论(2

┊风居住的梦幻卍 2025-01-15 04:15:52

startElement 方法有 Attributes 作为参数。您可以从该参数获取元素的属性。您可以参考此链接来获取示例

startElement method has Attributes as parameter. You can get attributes of element from that parameter. You may refer this link for example.

似狗非友 2025-01-15 04:15:52

如果您使用 android sax 版本那么您可以像这样进行

    text.setStartElementListener(new StartElementListener(){
                public void start(Attributes attr)
                {
                    String value = attr.getValue("author");

                    currentMessage.setAuthor(value.toString());
                }
        });

if your using the android sax version then you can go about it like this

    text.setStartElementListener(new StartElementListener(){
                public void start(Attributes attr)
                {
                    String value = attr.getValue("author");

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