Reputation: 497
i want create XML file here is my following code
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();
}
The above Same Code is Working Fine in JAVA project But In Android Project gives following Error
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)
Upvotes: 2
Views: 7487
Reputation: 8548
XMLStreamWriter
is in the javax.xml.stream.*
package. This package is not included in the default Android build. You can use it, but you have to repackage it in your app.
Description of your problem and a guide on how to repackage javax.* packages: http://code.google.com/p/dalvik/wiki/JavaxPackages
If you don't want to repackage XMLStreamWriter
in your app, try using XmlSerializer
which is included in Android. Excellent example right here on SO: Writing XML on Android
Upvotes: 6