我想在这里创建XML文件是我的以下代码
String fileName = "jasstech.xml";
XMLOutputFactory xof = XMLOutputFactory.newInstance();
XMLStreamWriter xtw = null;**
try
{
xtw = xof.createXMLStreamWriter(new FileOutputStream(fileName), "UTF-8");
xtw.writeStartDocument("UTF-8", "1.0");
xtw.writeStartElement("root");
xtw.writeComment("This is an attempt to create an XML file with StAX");
xtw.writeStartElement("foo");
xtw.writeAttribute("order", "1");
xtw.writeStartElement("meuh");
xtw.writeAttribute("active", "true");
xtw.writeCharacters("The cows are flying high this Spring");
xtw.writeEndElement();
xtw.writeEndElement();
xtw.writeStartElement("bar");
xtw.writeAttribute("order", "2");
xtw.writeStartElement("tcho");
xtw.writeAttribute("kola", "K");
xtw.writeCharacters("Content of tcho tag");
xtw.writeEndElement();
xtw.writeEndElement();
xtw.writeEndElement();
xtw.writeEndDocument();
}
catch (XMLStreamException e)
{
e.printStackTrace();
}
catch (IOException ie)
{
ie.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
以上相同代码在JAVA项目中工作正常但在Android项目中给出以下错误
03-03 07:48:40.778: ERROR/AndroidRuntime(719): Uncaught handler: thread main exiting due to uncaught exception
03-03 07:48:40.788: ERROR/AndroidRuntime(719): com.kochar.xml.stream.FactoryConfigurationError: Provider com.ctc.wstx.stax.WstxOutputFactory not found
03-03 07:48:40.788: ERROR/AndroidRuntime(719): at com.kochar.xml.stream.XMLOutputFactory.newInstance(XMLOutputFactory.java:23)
Run Code Online (Sandbox Code Playgroud)
XMLStreamWriter在javax.xml.stream.*包中.此软件包不包含在默认的Android版本中.您可以使用它,但必须在应用程序中重新打包它.
问题描述和如何重新打包javax.*包的指南:http: //code.google.com/p/dalvik/wiki/JavaxPackages
如果您不想XMLStreamWriter在自己的应用中重新打包,请尝试使用XmlSerializerAndroid中包含的内容.关于SO的优秀示例:在Android上 编写XML
| 归档时间: |
|
| 查看次数: |
6736 次 |
| 最近记录: |