XMLWriter xml header ( how to write)

283 views
Skip to first unread message

piza...@gmail.com

unread,
May 1, 2015, 9:22:32 AM5/1/15
to codenameone...@googlegroups.com
My question is this : How can I get XML writer to write the xml header
<?xml version="1.0" encoding="utf-8"?>
 
I have an set of Elements i.e. < tag1></tag1><tag2></tag2> etc etc.
which has been generated from  using XMLParser reading an xml file.
  - This gives <ROOT> <tags ....   /tags>.
After updateing the elements and values I now want to write the xml back to a file or a string.
 Element myElements ; // Already propogated element
 
        XMLWriter xmlWriter = new XMLWriter(false);
        StringWriter stringWriter = new StringWriter();
        xmlWriter.writeXML(stringWriter,myElements);
 
Do i need to create and Element "?XML" with the correct set attributes?
 - but this means a tag <?xml> </?xml>  which breaks xml headers
Or do I have to add the headerr string manually before using XMLwriter?
any ideas?
 

Shai Almog

unread,
May 1, 2015, 10:05:14 AM5/1/15
to codenameone...@googlegroups.com, piza...@gmail.com
Just use:

stringWriter.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");

Before passing the string writer to the writeXML method.

Its probably something we should add to the XMLWriter.
Reply all
Reply to author
Forward
0 new messages