The Android docs list  javax.xml.transform.TransformerFactory as being
available, though I've never tried it on Android.

On Aug 30, 6:43 am, saikiran n <saikiran....@gmail.com> wrote:
> Hi ,
>  I want to modify an xml file which is in sdcard dynamically.
> How can we acheive this in android. I have seen some java code as follows
>
> try {  
>         File file = new File("connections.xml");
>
>         //Create instance of DocumentBuilderFactory
>         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
>
>         //Get the DocumentBuilder
>         DocumentBuilder docBuilder = factory.newDocumentBuilder();
>
>         //Using existing XML Document
>         Document doc = docBuilder.parse(file);
>
>         //create the root element
>         Element root = doc.getDocumentElement();
>
>         //create child element
>         Element childElement = doc.createElement("number");
>
>         //Add the attribute to the child
>         childElement.setAttribute("id","3");
>         root.appendChild(childElement);
>
>         //set up a transformer
>         TransformerFactory transfac = TransformerFactory.newInstance();
>         Transformer trans = transfac.newTransformer();
>
>         //create string from xml tree
>         StringWriter sw = new StringWriter();
>         StreamResult result = new StreamResult(sw);
>         DOMSource source = new DOMSource(doc);
>         trans.transform(source, result);
>         String xmlString = sw.toString();
>
>         OutputStream f0;
>         byte buf[] = xmlString.getBytes();
>         f0 = new FileOutputStream("connections.xml");
>         for(int i=0;i<buf .length;i++) {
>            f0.write(buf[i]);
>         }
>         f0.close();
>         buf = null;
>      }
>      catch(SAXException e) {
>         e.printStackTrace();            
>      }
>      catch(IOException e) {
>         e.printStackTrace();            
>      }
>      catch(ParserConfigurationException e) {
>        e.printStackTrace();            
>      }
>      catch(TransformerConfigurationException e) {
>        e.printStackTrace();            
>      }
>      catch(TransformerException e) {
>        e.printStackTrace();            
>      }
>
> But The TransformerFactory class is not avalible in android sdk.
> How can we handle above code
> Any help please,
> Thanks in advance

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to