create and modify xml file using javascript

后端 未结 4 1650
故里飘歌
故里飘歌 2020-12-03 21:55

How do i create new xml file and also modify any xml file means add more nodes in xml file using javascript.?

Thanks in advance...

4条回答
  •  春和景丽
    2020-12-03 22:36

    I've found Ariel Flesler's XMLWriter constructor function to be a good start for creating XML from scratch, take a look at this

    http://flesler.blogspot.com/2008/03/xmlwriter-for-javascript.html

    Example

    function test(){    
       var v = new  XMLWriter();
       v.writeStartDocument(true);
       v.writeElementString('test','Hello World');
       v.writeAttributeString('foo','bar');
       v.writeEndDocument();
       console.log( v.flush() );
    }
    

    Result

    
    Hello World
    

    One caveat to keep in mind is that it doesn't escape strings.

    See also Libraries to write xml with JavaScript

提交回复
热议问题