I used to parse a wbxml traffic comes to my android device. i use kxml parser to print out the contents, but parser says me there isn't any string or attributes to show. where am i wrong ?
public static void main(String[] args) throws FileNotFoundException, XmlPullParserException, ParserConfigurationException, UnsupportedEncodingException, IOException, SAXException, TransformerConfigurationException, TransformerException {
// TODO code application logic here
File file = new File("path to wbxml file");
//InputStream in = new FileInputStream("path to wbxml file");
InputStream in = new DataInputStream(new FileInputStream(file));
ByteArrayInputStream bin = new ByteArrayInputStream(in.toString().getBytes());
WbxmlParser parser = new WbxmlParser();
parser.setInput(bin, "UTF-8");
int eventType = parser.getEventType();
while (eventType != WbxmlParser.END_DOCUMENT) {
if(eventType == WbxmlParser.START_DOCUMENT) {
//Log.d(a, "Start document");
System.out.printf("%s\n", "Start document");
} else if(eventType == WbxmlParser.START_TAG) {
//Log.d(a, "Start tag "+parser.getName());
System.out.printf("%s\n", parser.getName());
} else if(eventType == WbxmlParser.END_TAG) {
//Log.d(TAG, "End tag " + parser.getName());
System.out.printf("%s\n", parser.getName());
} else if(eventType == WbxmlParser.TEXT) {
//Log.d(TAG, "Text " +parser.getText());
System.out.printf("%s\n", parser.getText());
}
eventType = parser.next();
}
System.out.println("End document");
//try{
Document doc = new Document();
doc.parse(parser);
//} catch (XmlPullParserException e){
// e.printStackTrace();
// }
ByteArrayOutputStream out = new ByteArrayOutputStream();
KXmlSerializer ser = new KXmlSerializer();
ser.setOutput(out, null);
doc.write(ser);
ser.flush();
byte[] b = out.toByteArray();
System.out.println(new String(b));
/*TransformerFactory tfactory = TransformerFactory.newInstance();
Transformer transformer = tfactory.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(System.out);
transformer.transform(source, result); */
}
I also checked Heiner's Blog for answer but nothing... wbxml document i want to parse is sth like this.