写入服务器上的XML文件

时间:2012-04-08 21:26:55

标签: javascript html xml comments

我一直在几个网站上工作,需要你的帮助。我想知道是否有办法使用javascript或HTML写入服务器上的XML文件。我在网上搜索了答案,但似乎无法找到答案。 谢谢,怀亚特

2 个答案:

答案 0 :(得分:0)

HTML不是一种编程语言,它不能写任何东西。

如果您想使用JavaScript,那么您需要使用服务器端JavaScript。这些天SSJS的常用工具是node.jsfile system模块允许您写入磁盘。

答案 1 :(得分:-2)

我不知道通过javascript客户端编写xml的可能性。 但在服务器端,我知道你可以通过php写。 如果你想我附上例子。我希望我帮助你。

<?php

function fnDOMAddElement2Start($doc='')
    {
        if(!$doc)
        {
            $doc = new DOMDocument();
            $doc->load('Dictionary_user.xml');
        }
        $Dictionary_user = $doc->documentElement;
        #var_dump($Dictionary_user->childNodes->item(0)->parentNode->nodeName);
        $newWord = $doc->createElement('newWord');
        #$newWord->setAttribute('isbn','http-equiv="Content-Type" content="text/html; CHARSET=windows-1255"');


        $prop = $doc->createElement('Heb','bull');
        $newWord->appendChild($prop);
        $prop = $doc->createElement('Eng','bu');
        $newWord->appendChild($prop);


        $Dictionary_user->childNodes->item(0)->parentNode->insertBefore($newWord,$Dictionary_user->childNodes->item(0));
        header("Content-type: text/xml");
        echo $doc->saveXML();
        $doc->save("Dictionary_user.xml");
    }
fnDOMAddElement2Start();
    ?>

xml文件似乎是:

<?xml version="1.0"?>
<Dictionarys>
  <newWord>
    <Heb>bull</Heb>
    <Eng>bu</Eng>
  <newWord>
    <Heb>Dog</Heb>
    <Eng>DO</Eng>
  </newWord>
  <newWord>
    <Heb>Cat</Heb>
    <Eng>ca</Eng>
  </newWord>
</Dictionarys>
相关问题