Create XML in Javascript

后端 未结 7 689
慢半拍i
慢半拍i 2020-11-28 07:16

I\'m wondering, is it possible to create an XML file with some data in Javascript? I have the data stored in variables.

I\'ve googled around a bit and it doesn\'t see

相关标签:
7条回答
  • 2020-11-28 07:50

    Your code is referencing this library

    You can include it, and then your code in question should run as is. If you want to do this without prepending the library & build it with builtin functions only - follow answer from @Seb3736.

    In Browser Example

    <html>
    <head>
        <script src="Global.js" language="javascript"></script>
        <script src="XMLWriter.js" language="javascript"></script>
        <script language="javascript" type="text/javascript">
            function genXML(){
                var XML = new XMLWriter();
                XML.BeginNode ("testing");
                XML.Node("testingOne");
                XML.Node("TestingTwo");
                XML.Node("TestingThree");
                XML.EndNode();
                //Do something... eg.
                console.log(XML.ToString); //Yes ToString() not toString()
            }
        </script>
    </head>
    <body>
        <input type="submit" value="genXML" onclick="genXML();">
    </body>
    </html>
    
    
    0 讨论(0)
提交回复
热议问题