普通的JAVA XML解析包比较大,占用资源比较多,不适合嵌入式设备使用
KXML是专门用在嵌入式设备上,只有十几K
下面是我在实际项目中用到的一代码,供大家参考
public String XmlDecoding(DataInputStream din) throws IOException{
String temp = null;
Reader reader = new InputStreamReader(din);
XmlParser parser = new XmlParser(reader);
ParseEvent pe = null;
parser.read(Xml.START_TAG, null, "upos");
parser.skip();
ParseEvent event = null;
do {
try {
event = parser.read ();
if(event.getType()==Xml.START_TAG) {
String name = event.getName();
temp += "<"+name + ">\n";
}
if(event.getType()== Xml.TEXT) {
String name = event.getText();
name = name.trim();
temp += name + "\n";
}
if(event.getType()== Xml.END_TAG) {
String name = event.getName();
temp += "<"+name + ">\n";
}
}
catch(IOException ex) {
System.out.println("Exception occured");
}
}
while (event.getType() != Xml.END_DOCUMENT);
return temp;
}