写到原来的位置,是不安全的,所以不能。
不过你可以在xml对象里创建节点.
不过你可以在xml对象里创建节点.
解决方案 »
- 用JQUERY比较表格中每行的第二个和第三个单元格的值是否相等
- JS保留2位小數BUG
- tempday=round(rs("endtime")-now()) now括弧里应该填什么值
- 关于函数定义的问题,有一点不明白了,请赐教,谢谢!
- 如何实现自动完成功能?
- 请教一个简单的函数,求帮助
- 急啊!!这个怎么赋值???
- document.location和window.location有什么区别,最好能举例说明~
- 如何统计,提交后,checkbox 选择的个数
- js可以调用2000的信使服务么?
- 三级下拉列表框联动,提交数据库的问题(请孟子E章,希若等专家高手帮忙,参与者有分!)
- 求救 netScape 4.7
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"))
%>
比如:
replaceChild(),appendChild(),removeChild()等方法,具体参照xml sdk
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
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);
对了。。还有一个问题如果我的hit是从xml中的一个节点中提取的一个数字, 如 30
那么hit+1 怎么是301?
要怎么才是31?
xml.save()吗?
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")
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