I really have a problem: When I want to parse this XML file:
XML file:
<marketexport>
<createtime_timestamp>1236801648</createtime_timestamp>
<createtime_date>11.03.09 - 21:00</createtime_date>
<ressources>
<ressource>
<name>Energie</name>
<price>14</price>
<number>11967033</number>
</ressource>
</ressources>
<race>
<race_name>Nova Federation</race_name>
<military_units>
<unit>
<name>NoF Marine</name>
<price>1200</price>
<number>845</number>
</unit>
</military_units>
<spy_units>
<unit>
<name>Thief</name>
<price>0</price>
<number>0</number>
</unit>
<unit>
<unit>
<name>Agent</name>
<price>0</price>
<number>0</number>
</unit>
</spy_units>
</race>
</marketexport>
ExampleHandler:
public void startElement(String namespaceURI, String localName,
String qName, Attributes atts) throws SAXException {
if (localName.equals("marktexport")) {
this.in_marktexport = true;
}
if (localName.equals("ressources")) {
this.in_ressources = true;
}
if (localName.equals("ressource")) {
this.in_ressource = true;
}
if (localName.equals("race")) {
this.in_race = true;
}
if (localName.equals("race_name")) {
this.in_race_name = true;
}
if (localName.equals("military_units")) {
this.in_military_units = true;
}
if (localName.equals("unit")) {
this.in_unit = true;
}
if (localName.equals("name")) {
this.in_name = true;
}
if (localName.equals("price")) {
this.in_price = true;
}
if (localName.equals("number")) {
this.in_number = true;
}
}
public void endElement(String namespaceURI, String localName,
String qName)
throws SAXException {
if (localName.equals("marktexport")) {
this.in_marktexport = false;
}
if (localName.equals("ressources")) {
this.in_ressources = false;
}
if (localName.equals("ressource")) {
this.in_ressource = false;
}
if (localName.equals("name")) {
this.in_name = false;
}
if (localName.equals("price")) {
this.in_price = false;
}
if (localName.equals("number")) {
this.in_number = false;
}
if (localName.equals("race")) {
this.in_race = false;
}
if (localName.equals("race_name")) {
this.in_race_name = false;
}
if (localName.equals("military_units")) {
this.in_military_units = false;
}
if (localName.equals("unit")) {
this.in_unit = false;
}
}
public void characters(char ch[], int start, int length) {
if(this.in_race_name){
myParsedExampleDataSet.setrace(new String(ch, start,
length));
}
if(this.in_name){
myParsedExampleDataSet.setname(new String(ch, start,
length));
}
if(this.in_price){
myParsedExampleDataSet.setprice(new String(ch,
start, length));
}
if(this.in_number){
myParsedExampleDataSet.setnumber(new String(ch,
start, length));
}
}
ParsedExampleDataSet:
public void setprice(String price){
this.price = price;
}
public void setname(String name) {
this.name = name;
}
public void setnumber(String number) {
this.number = number;
}
public void setrace(String race) {
this.race = race;
}
//Getter
public String getnumber() {
return number;
}
public String getprice() {
return price;
}
public String getname() {
return name;
}
public String getrace() {
return race;
}
//.toString()
public String toString() {
result = getrace()+"\nName: "+getname()+"\nPreis: "+getprice()
+"\nNumber: "+getnumber();
return result;
}
I Only get:
Nova Federation
Name: Agent
Preis: 0
Anzahl: 0
So I want to get:
Nova Federation
Name: NoF Marine
Preis: 1200
Number: 845
Perhaps someone can help me with my problem Smile
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---