xml解析问题!急
我是利用axiom对xml进行解析!
但却出现下面的错误!
Exception in thread "main" org.apache.axiom.om.OMException: [com.ctc.wstx.exc.WstxLazyException] com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character ' ' (code 32) (missing name?)
at [row,col {unknown-source}]: [136,53]
程序在执行有些xml文件时没有问题,有些却有问题。我很苦恼!是不是我的xml文件有问题啊?
Java code:
public class AxiomDemo {
public static void writeToFile(OutputStream os, byte[] b) {//写内容写到文件里面
try {
os.write(b, 0, b.length);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void writeToFile(OutputStream os, OMElement om) {
try {
String str = om.toStringWithConsume();
byte[] b = str.getBytes();
//os.write(b, 0, b.length);
writeToFile(os, b);
} catch (XMLStreamException e) {
// TODO: handle exception
}
}
public static OMElement readQuestionXml(InputStream is) {
OMElement om = null;
try {
XMLStreamReader parser = XMLInputFactory.newInstance()
.createXMLStreamReader(is);
StAXOMBuilder builder = new StAXOMBuilder(parser);
相关问答:
<?xml version="1.0" encoding="utf-8" ?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical&q ......
我有一个类似的xml的 string,想通过遍历怎么个xml 输出我想要的element的值
xml 为:
<Discover xmlns="urn:schemas-microsoft-com:xml-analysis">
<RequestType>DISCOVER_XML_ME ......
XML_PARSER_STRUCT parser;
ret = xml_new_parser(&parser);
xml_register_element_handler(&parser, mmi_pict_read_xml_start_element_login, mmi_pict_read_xml_end_element_lo ......
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<id="1">
<user="test1" pass="12345" />
& ......