0

Possible Duplicate:
Parse local XML file in Android

hi. I want to know how to load and how to parse this XML file from res/xml, and how to rewrite the values

<?xml version="1.0" encoding="UTF-8"?>
<Rocket>
    <body>baby</body>
    <launcher>basic</launcher>
    <point>0</point>
    <money>0</money>
    <highest>0</highest>
    <levelReached>1</levelReached>
</Rocket>

I've never playing with XML before so I feel so blind about this. I already done searching and all I found is about reading XML files from the internet. I didn't find any tutorial of how to parse xml for game use.

and for the additional question,I don't really understand the terms in xml. what is the meaning of serialization? what is DOM? SAXParser? PullParser?

Community
  • 1
  • 1
Fugogugo
  • 4,460
  • 10
  • 36
  • 50
  • Looks like a repeat of this question http://stackoverflow.com/questions/1372470/parse-local-xml-file-in-android – chaitanya Apr 08 '11 at 17:01
  • no it's not. I found no satisfying answer in there. – Fugogugo Apr 08 '11 at 17:06
  • please. it's not for data exchange purpose – Fugogugo Apr 08 '11 at 17:30
  • Why is the answer at the duplicate question not satisfying? Seems like a pretty good approach to me. – Robert Harvey Apr 08 '11 at 17:58
  • because I still not find answer of how to rewrite the value. and I need some sample code of the implementation. as I mentioned before, I really have no idea – Fugogugo Apr 08 '11 at 18:06
  • Ah, I see. Well, as with many things Android, Google is of great help here. Have a look at this Google search: http://www.google.com/#sclient=psy&hl=en&site=&source=hp&q=read+and+write+xml+files+android – Robert Harvey Apr 08 '11 at 18:14

1 Answers1

0

DOM is a generic in-memory representation (nodes and pointers) of you XML data. SAX is a parsing API that generates (pushes) parsing events while streaming the XML input file. PullParser is similar but pull-based.

If you just want to get "that data" into your code you might want to go for XML data binding: http://en.wikipedia.org/wiki/XML_data_binding

It will generate source code of classes matching the structure of the XML data. Afterwards you can easily convert XML to objects and back. That's called (un)marshalling and is similar to (de)serialization.

Jonas Bötel
  • 4,452
  • 1
  • 19
  • 28
  • is there any example of how to do that XML data binding in android? I don't understand about xml at all – Fugogugo Apr 08 '11 at 18:09