0

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

3
  • is sax a requirement? it is somewhat hard to use, you can use xpath with sax Commented Mar 5, 2011 at 8:42
  • @vtd-xml-author can you share an example of how it can be done using xpath ? Commented Jan 9, 2013 at 20:04
  • you can't use xpath with sax Commented Jan 29, 2013 at 1:47

2 Answers 2

5

just go through

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

you will also get code to download..

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.