faqts : Computers : Programming : Languages : JavaScript : XML

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

145 of 192 people (76%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

How can I create an XML document object?

Feb 15th, 2009 21:36
Inschi jelii, Martin Honnen,


With IE5 you can create the document object with
  var xmlDocument = new ActiveXObject('Microsoft.XMLDOM');
Then you create and set the root element, documentElement, e.g.
  var root = xmlDocument.createElement('gods');
  xmlDocument.documentElement = root;
To this documentElement you can then add further nodes with DOM methods
  var god = xmlDocument.createElement('god');
  god.setAttribute('name', 'Kibo');
  god.setAttribute('home', 'http://www.kibo.com');
  xmlDocument.documentElement.appendChild(god);
With NN6/7, Mozilla, Firebird, and with Opera 7.60 and later you can
create the document object including root element with
  var xmlDocument = 
    document.implementation.createDocument('', 'rootElementName', null)
e.g.
  var xmlDocument = 
    document.implementation.createDocument('', 'gods', null);
Then you use DOM methods to add further elements
  var god = xmlDocument.createElement('god');
  god.setAttribute('name', 'Kibo');
  god.setAttribute('home', 'http://www.kibo.com');
  xmlDocument.documentElement.appendChild(god);
http://lahjatideoita.blogspot.com
http://ideaspara-regalar.blogspot.com
http://idearegalo1.blogspot.com
http://geschenkeidee.blogspot.com
http://darkovenapady.blogspot.com