Creating and modifying XML file
Posted: November 27th, 2014, 5:28 am
Does anyone have some examples on how to create an XML file and modify it (adding elements and such)?
I know the basics but i've mostly dealt with modification of existing XML files in the past, not creating one from the scratch.
Also, i figured .appendChild(), but when i read XML file, append some element and write the modified XMl into a file, i lose the declaration for some reason.
This:
Becomes this:
Notice the missing declaration at line 1.
Any help appreciated.
I know the basics but i've mostly dealt with modification of existing XML files in the past, not creating one from the scratch.
Also, i figured .appendChild(), but when i read XML file, append some element and write the modified XMl into a file, i lose the declaration for some reason.
This:
Code: Select all
<?xml version="1.0"?>
<root>
<something1></something1>
</root>
Code: Select all
<root>
<something1></something1>
<something2></something2>
</root>
Any help appreciated.