Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create xml file from a string in android
    primarykey
    data
    text
    <p>I am trying to get an XML file from a String in android, the code is constantly giving me an exception. Below is my Code</p> <pre><code>public void createXML (String xmlString) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder; try { builder = factory.newDocumentBuilder(); // Use String reader Document document = builder.parse( new InputSource( new StringReader( xmlString ) ) ); TransformerFactory tranFactory = TransformerFactory.newInstance(); Transformer aTransformer = tranFactory.newTransformer(); Source src = new DOMSource( document ); String path = "ScriptEmails/"+ "my"+".xml"; String filepath = Environment.getExternalStorageDirectory().toString()+File.separator+"Screenwriter"+File.separator+path; Result dest = new StreamResult( new File( filepath ) ); aTransformer.transform( src, dest ); } catch (Exception e) { // TODO Auto-generated catch block e.toString(); } } </code></pre> <p>I get exception on this line <code>Document document = builder.parse( new InputSource( new StringReader( xmlString ) ) );</code> </p> <p>My <code>xmlString</code> contain the following value</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="no" ?&gt; &lt;FinalDraft DocumentType="Script" Template="No" Version="1"&gt; &lt;Paragraph Type =Scene Heading&gt; &lt;Text&gt; HELLO &lt;/Text&gt; &lt;/Paragraph&gt; &lt;Paragraph Type =Action&gt; &lt;Text&gt; HELLO This is my first scene &lt;/Text&gt; &lt;/Paragraph&gt; &lt;Paragraph Type =Character&gt; &lt;Text&gt; HELLO This is my first scene HASS &lt;/Text&gt; &lt;/Paragraph&gt; &lt;Paragraph Type =Dialogue&gt; &lt;Text&gt; HELLO This is my first scene HASS Cheetay kesa hay Kia scene &lt;/Text&gt; &lt;/Paragraph&gt; &lt;Paragraph Type =Dialogue&gt; &lt;Text&gt; HELLO This is my first scene HASS Cheetay kesa hay Kia scene chal rha hay ajkel &lt;/Text&gt; &lt;/Paragraph&gt; &lt;Paragraph Type =Character&gt; &lt;Text&gt; HELLO This is my first scene HASS Cheetay kesa hay Kia scene chal rha hay ajkel AHNE &lt;/Text&gt; &lt;/Paragraph&gt; &lt;Paragraph Type =Dialogue&gt; &lt;Text&gt; HELLO This is my first scene HASS Cheetay kesa hay Kia scene chal rha hay ajkel AHNE Kuch nhe boy scene is really &lt;/Text&gt; &lt;/Paragraph&gt; &lt;Paragraph Type =Dialogue&gt; &lt;Text&gt; HELLO This is my first scene HASS Cheetay kesa hay Kia scene chal rha hay ajkel AHNE Kuch nhe boy scene is really baf actually things have gotten &lt;/Text&gt; &lt;/Paragraph&gt; &lt;Paragraph Type =Dialogue&gt; &lt;Text&gt; HELLO This is my first scene HASS Cheetay kesa hay Kia scene chal rha hay ajkel AHNE Kuch nhe boy scene is really baf actually things have gotten worse &lt;/Text&gt; &lt;/Paragraph&gt; &lt;/FinalDraft&gt; </code></pre> <p>Let me know if something is wrong with my code or with my xmlString.</p> <p>Here is the LogCat</p> <pre><code>12-06 12:06:56.983: W/System.err(28508): org.xml.sax.SAXParseException: attr value delimiter missing! (position:START_TAG &lt;Paragraph Type='Script'&gt;@4:18 in java.io.StringReader@4239c190) 12-06 12:06:56.983: W/System.err(28508): at org.apache.harmony.xml.parsers.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:146) 12-06 12:06:56.983: W/System.err(28508): at com.example.screenwritter.Dropboxupload.createXML(Dropboxupload.java:356) 12-06 12:06:56.983: W/System.err(28508): at com.example.screenwritter.Dropboxupload$4.onClick(Dropboxupload.java:339) 12-06 12:06:56.983: W/System.err(28508): at android.view.View.performClick(View.java:3574) 12-06 12:06:56.983: W/System.err(28508): at android.view.View$PerformClick.run(View.java:14293) 12-06 12:06:56.983: W/System.err(28508): at android.os.Handler.handleCallback(Handler.java:605) 12-06 12:06:56.983: W/System.err(28508): at android.os.Handler.dispatchMessage(Handler.java:92) 12-06 12:06:56.983: W/System.err(28508): at android.os.Looper.loop(Looper.java:137) 12-06 12:06:56.983: W/System.err(28508): at android.app.ActivityThread.main(ActivityThread.java:4448) 12-06 12:06:56.983: W/System.err(28508): at java.lang.reflect.Method.invokeNative(Native Method) 12-06 12:06:56.983: W/System.err(28508): at java.lang.reflect.Method.invoke(Method.java:511) 12-06 12:06:56.983: W/System.err(28508): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823) 12-06 12:06:56.993: W/System.err(28508): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590) 12-06 12:06:56.993: W/System.err(28508): at dalvik.system.NativeStart.main(Native Method) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload