+ -
当前位置:首页 → 问答吧 → 用createNode 方法创建的xml节点怎么保存到xml文件中啊?

用createNode 方法创建的xml节点怎么保存到xml文件中啊?

时间:2004-12-08

来源:互联网

用createNode 方法创建的xml节点怎么保存到xml文件中啊?
好像创建了只是在这个浏览器中有效啊,打开xml文件,一点不变,而且刷新了后什么也没了

作者: wps2000   发布时间: 2004-12-08

还有有通过节点值寻找节点的方法吗?

作者: wps2000   发布时间: 2004-12-08

你有没有执行xmlDoc.save("file.xml")?

作者: 泣红亭   发布时间: 2004-12-09

我在地本写了一个HTML的脚本,里面用VBSCRIPT对XML进行操作,最后保存时提示我没有权限,请问更改什么设置能让我有保存的权限?

作者: zqsoft   发布时间: 2005-05-23

Node getElementByAttributeValue(Node n, DOMString attName, DOMString attVal)
{
        Node theNode = null;
        // if this node matches the given attribute name and value,
        // then we can return it.
        if(n.getNodeType() == Node.ELEMENT_NODE)
        {
                if((Element)n).getAttribute(attName).equals(attVal))
                        return n;
        }
        // otherwise process all of the child nodes.
        for((Node c = n.firstChild(); c != null && ! theNode; c = c.nextSibling())
        {
                theNode = getElementByAttributeValue(c, attName, attVal);
        }
        return theNode;
}

// Example:
// Node the Node = getElementByAttributeValue(document.documentElement, "myattr", "myattrvalue");


///////////////////////////////////////////////////////////

Vector getElementByAttributeValue(Node n, DOMString attName, DOMString attVal)
{
        Vector theNodes = new Vector();
        addNodesToList(n, theNodes, attName, attVal);
        return theNodes;
}

addNodesToList(Node n, Vector v, DOMString attName, DOMString attVal)
{
        // if this node matches the given attribute name and value,
        // then add it to the list of notes.
        if(n.getNodeType() == Node.ELEMENT_NODE)
        {
                if((Element)n).getAttribute(attName).equals(attVal))
                        v.add(n);
        }
        // now recursively process all of the nodes' child nodes
        for(Node c = n.firstChild(); c != null; c = c.nextSibling())
        {
                addNodesToList(c, v, attName, attVal);
        }
}

作者: 塞北风   发布时间: 2005-05-24

DOM Level 1 和 DOM Level 2 的规范中都没有提供从 DOM 实在加载和保存文档,以及加载和保存文档到 DOM 实现的方法。这部分是故意留下来作为一个依赖实现的函数,一些 DOM 实现,例如 Macromedia、Apache、Microsoft 和 Netscape 已经定义了他们自己用于加载和保存文档的接口和方法。当然结果是并非所有的 DOM 实现都为文档的持久性使用同样的方法。例如,在 Macromedia 的 Dreamweaver DOM 实现中通过一个名为 openDocument() 的方法来加载文档,而该方法在 Microsoft Internet Explorer 中被命名为 load()。

当然还有其它许多的内容,实在太多了,可能在 DOM Level 3 中这些会有完整的实现。

贴个 IDL 规范:
interface DocumentLS{
  attribute boolean async; // raises DOMException on setting
  void abort();
  boolean load(in DOMString URI);
  boolean loadXML(in DOMString source);
  DOMString saveXML(in Node snode) raises (DOMException);
}

// emulate the saveXML method
Document.prototype.saveXML = doc__saveXML;
Function doc__saveXML()
{
        var s = new XMLSerializer();
        var xmlStr = s.serializeToString(this);
        return xmlStr;
}

// emulate the loadXML() method
Document.prototype.loadXML = doc__loadXML;
function doc__loadXML(xmlStr)
{
        var domParser = new DOMParser();
        var newDoc = domParser.parseFromString(xmlStr, "text/xml");
        // the current document needs to have all of its nodes replaced
        while(this.childNodes.length > 0)
                this.removeChild(this.firstChild);
        // now all of the new child nodes need to be appended
        // to the existing document.
        this.appendChild)this.importNode(newDoc.documentElement, true));
}

作者: 塞北风   发布时间: 2005-05-24

save() 在本地不能用(会提示没权限). 在服务器上用 ASP 等语言才能执行.

作者: ※潇洒※   发布时间: 2005-05-28