我需要把下面的 xml 解析 為輸出:
String id="3"
String name="str1"
String path="/mnt/sdcard/path2"
String type="2"
String desc="des3)"
在 android中如何實現呢?
<xmldump>
<mfs id="3" name="str1" path="/mnt/sdcard/path2" type="2" desc="des3)" />
<mfs id="1" name="st2" path="/mnt/sdcard/path1" type="2" desc="des2" />
<mfs id="2" name="stvr3" path="/mnt/sdcard/path3" type="2" desc="des1" />
</xmldump>
請參考這個例子:
<?xml version="1.0" encoding="UTF-8"?>
<Personnel>
<Employee type="permanent">
<Name>Seagull</Name>
<Id>3674</Id>
<Age>34</Age>
</Employee>
<Employee type="contract">
<Name>Robin</Name>
<Id>3675</Id>
<Age>25</Age>
</Employee>
<Employee type="permanent">
<Name>Crow</Name>
<Id>3676</Id>
<Age>28</Age>
</Employee>
</Personnel>
從解析內容中創建一個 Employee對象的列表,然後再打印出來。輸出結果如下:
Employee Details - Name:Seagull, Type:permanent, Id:3674, Age:34.
Employee Details - Name:Robin, Type:contract, Id:3675, Age:25.
Employee Details - Name:Crow, Type:permanent, Id:3676, Age:28.
http://www.java-samples.com/showtutorial.php?tutorialid=152