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.
精彩评论