我曾经解析过一个wbxml流量来到我的android设备。 我使用kxml解析器打印出内容,但解析器说我没有要显示的任何字符串或属性。 我哪里错了?
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); */
}
我还检查了Heiner's Blog的答案,但没有... 我要解析的wbxml文档就像this一样。