简体   繁体   中英

XML Parsing with SAX Parser in android

Hi I am AS3 Developer and now working in android. I have to load and parse a simple local XML.. i need simple program which can load and trace the nodes.

<rootelement1>
    <subelement item="First">
            <element>
            Hello XML Sub-Element 1
            </element>
    </subelement>
    <subelement>
        <element>
            Hello XML Sub-Element 2
        </element>
        <subsubelement>Sub Sub Element</subsubelement>
    </subelement>
</rootelement1>

How can i access the value of inner nodes with refrence to outer nodes and all that..

just go through

http://www.androidpeople.com/android-xml-parsing-tutorial-using-saxparser/

you will also get code to download..

Don't use the official Google way of using the pull parser directly - the API is too low-level, hard to use and error-prone. Google Android-related advices are usually garbage. Instead try Konsume-XML instead:

val file = File("src/test/files/rootelement.xml")
file.konsumeXml().use { k ->
    k.child("rootelement1") {
        child("subelement") {
            val item = attributes.getValueOpt("item")
            val e = childText("element")
            println(item); println(e)
        }
        child("subelement") {
            println(childText("element"))
            println(childText("subsubelement"))
        }
    }
}

This will print

First
Hello XML Sub-Element 1
Hello XML Sub-Element 2
Sub Sub Element

It's just a Kotlin code and function calls, nothing special, no annotations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM