I have a airport-codes.xml file :-
<?xml version="1.0" encoding="utf-8" ?>
<iata>
<iata_airport_codes>
<airport>Ocho Rios, Jamaica</airport>
<code>OCJ</code>
</iata_airport_codes>
</iata>
I want to add node by using javascript i use this code to add node
var xml = new ActiveXObject("Microsoft.XMLHTTP");
xml.open("GET", "airport-codes.xml", true);
xml.send(null);
var iata_airport_codes = xml.responseXML.createElement("iata_airport_codes");
var airport = xml.responseXML.createElement("airport");
airport.appendChild(xml.responseXML.createTextNode("Mr Njoroge"));
var code = xml.responseXML.createElement("code");
code.appendChild(xml.responseXML.createTextNode("21454741"));
iata_airport_codes.appendChild(airport);
iata_airport_codes.appendChild(code);
xml.responseXML.appendChild(iata_airport_codes);
but i got this error :-
Only one top level element is allowed in an XML document.
You try to add an element at the top level of the document. You just can add an element in the “iata” node.
So try :
EDIT : bad syntax in the code