写到原来的位置,是不安全的,所以不能。
不过你可以在xml对象里创建节点.

解决方案 »

  1.   

    Loading and Saving XML
    The load method can be used to load an XML file by pathname, URL, or as an IIS Request object. The following example loads an XML file by URL:XMLDoc.load("http://xmlfiles/reports.xml")
    The document object, XMLDoc, now contains a tree consisting of the parsed contents of reports.xml.You can also load an XML file as a string using the loadXML method.XMLDoc.loadXML("<customer><first_name>Joe</first_name>
      <last_name>Smith</last_name></customer>")
    The loading and parsing of an XML file occurs asynchronously by default (you can choose to load the XML file synchronously by setting the async property to false). To abort an asynchronous download, call the abort method on the document object.You can also assign a new document to a document object by assigning the document a new root element using the documentElement property.XMLDoc.documentElement = XMLNode
    It is important to remember that assigning the document object a new document element does not change the other children of the document. For instance, the doctype element will not change.To save a parsed XML document to a file or to another object, you can use the save method. The save method takes either a file name as a string, an Active Server Pages (ASP) Response object, an XMLDOMDocument object, or any custom object that supports persistence. The following example is part of an ASP file that saves the XML document to a file.<%
      dim xmldoc
      set xmldoc = Server.CreateObject("Microsoft.XMLDOM")
      xmldoc.async = false
      xmldoc.load(Request)
      xmldoc.save(Server.MapPath("sample.xml"))
    %>
      

  2.   

    把xml看成是DOM对象,就可以用DOM提供方法任意操纵xml里的内容了。
    比如:
    replaceChild(),appendChild(),removeChild()等方法,具体参照xml sdk
      

  3.   

    可能有用的就是replaceChild()了。。能举个实例吗?
      

  4.   

    to qiushuiwuhen(秋水无恨) 我要的不是asp如果是asp的话,我直接用fso就可以完成了。。呵呵。
      

  5.   

    <script>
    function test()
    {
    var xmldom = new ActiveXObject("Msxml2.DOMDocument")
    xmldom.async = false;
    xmldom = document.all.mxh.XMLDocument
    }
    function test2()
    {
    var xmldom = new ActiveXObject("Msxml2.DOMDocument")
    xmldom.async = false;
    xmldom = document.all.mxh.XMLDocument
    node = xmldom.selectSingleNode("//nodeB")
    alert(node.text)
    node2 = xmldom.createElement("nodeB")
    node2.text="AAAAA"
    xmldom.documentElement.replaceChild(node2,node)
    node = xmldom.selectSingleNode("//nodeB")
    alert(node.text)
    alert(xmldom.xml)
    }
    </script>
    <body>
    <XML id=mxh>
    <root>
    <nodeA>nodeA</nodeA>
    <nodeB>nodeB</nodeB>
    </root>
    </XML>
    <input onclick="test()" type="button" value=old>
    <input onclick="test2()" type="button" value=new>运行环境:xml3 或 xml4
      

  6.   

    用法:
    set objXMLDOMNode = objXMLDOMNode.replaceChild(newChild, oldChild)例子:
    var xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
    var root;
    var newElem;
    xmlDoc.async = false;
    xmlDoc.resolveExternals = false;
    xmlDoc.load("books.xml");
    root = xmlDoc.documentElement;
    newElem = xmlDoc.createElement("PAGES");
    root.childNodes.item(1).replaceChild(newElem, root.childNodes.item(1).childNodes.item(0));
    alert(root.childNodes.item(1).xml);
      

  7.   

    可是不能写入xml文件中啊。
    对了。。还有一个问题如果我的hit是从xml中的一个节点中提取的一个数字, 如 30
    那么hit+1 怎么是301?
    要怎么才是31?
      

  8.   

    new number吧。。我已经把数字搞定了。。xml的保存方法是?我就是要保存到服务器啊。
    xml.save()吗?
      

  9.   

    保存到服务器需要form的提交或用xmlhttp来做
      

  10.   

    <script>
    var xmldom
    function test()
    {
    xmldom = new ActiveXObject("Msxml2.DOMDocument")
    xmldom.async = false;
    xmldom = document.all.mxh.XMLDocument
    }
    function test2()
    {
    var xmldom = new ActiveXObject("Msxml2.DOMDocument")
    xmldom.async = false;
    xmldom = document.all.mxh.XMLDocument
    node = xmldom.selectSingleNode("//nodeB")
    node2 = xmldom.createElement("nodeB")
    node2.text=parseInt(node.text)+1
    xmldom.documentElement.replaceChild(node2,node)
    node = xmldom.selectSingleNode("//nodeB")
    alert(node.text)
    alert(xmldom.xml)
    }
    function test3()
    {
    document.f.xmldata.value= document.all.mxh.XMLDocument.xml
    alert(document.f.xmldata.value)
    document.f.submit()
    }
    </script>
    <body>
    <XML id=mxh>
    <root>
    <nodeA>nodeA</nodeA>
    <nodeB>30</nodeB>
    </root>
    </XML>
    <form name=f action="xx.asp">
    <input name=xmldata type=hidden>
    <input onclick="test()" type="button" value=old>
    <input onclick="test2()" type="button" value=请多点几次看看>
    <input onclick="test3()" type="button" value=保存>
    </form>
    如果要保存,可以调用 xmldom.save("xxx.xml")
      

  11.   

    <script language="javascript">
    var xml = new ActiveXObject("Msxml2.DOMDocument");
    xml.async = false;
    xml.load("1029.xml");
    var xsl = new ActiveXObject("Msxml2.DOMDocument");
    xsl.async = false;
    xsl.load("3.xsl");
    var content = xml.transformNode(xsl);
    document.write(content);
    nodes = xml.documentElement.childNodes; 
    XMLDATA.content = xml.xml;
    var hit = xml.selectSingleNode("//hit");
    var newhit = hit;
    newhit.text = new Number(hit.text) + 1;
    xml.documentElement.replaceChild(newhit,hit);
    alert(hit.text);
    xml.save("1029.xml");
    </script>提示没有权限?我已经把everyone的完全控制开了。http://www.5inet.net/article/view.stm?1029