//以前写过的,现在重新写了一下,源码开放,使用的人请将扩充项回帖,谢谢
/*
coment: Java Xml Writer Class
editer: gujin
date: 2005-03-01
*/
//创建Xml文档并将它加入Dom中
function clsXmlWriter(){
/***公共成员变量***/
//Dom成员对象
this.oXMLDom = new ActiveXObject("Microsoft.XMLDOM");
this.oXMLDom.async = false
/***公共成员函数***/
this.CreateXmlDom = c_CreateXmlDom;
this.insertNode = c_insertNode;
this.AppendNode = c_AppendNode;
this.removeNode = c_removeNode;
this.AppendAttributeValue = c_AppendAttributeValue;
this.UpdateAttributeValue = c_UpdateAttributeValue;
this.removeAttributeValue = c_removeAttributeValue;
}
function c_CreateXmlDom(oXMLDom,rootname){
oXMLDom.loadXML("<" + rootname + "//>");
//创建根节点
//var root=oXMLDom.createElement("MyRoot");
//oXMLDom.documentElement = root
}
//插入指定位置节点
function c_insertNode(oXMLDom,XmlNode,nodeName,nodeText,Before){
if (XmlNode!=null){
var NewNode = oXMLDom.createNode(1, nodeName,"");
NewNode.text=nodeText;
if (Before){
XmlNode.parentNode.insertBefore(NewNode,XmlNode)
return NewNode
}
else{
XmlNode.parentNode.appendChild(NewNode);
return NewNode
}
}
}
//添加节点
function c_AppendNode(oXMLDom,XmlNode,nodeName,nodeText){
if (XmlNode!=null){
var NewNode = oXMLDom.createNode(1, nodeName,"");
NewNode.text=nodeText;
XmlNode.appendChild(NewNode);
return NewNode
}
}
//移除节点
function c_removeNode(removenode){
if (node!=null) removenode.parentNode.removeChild(removenode);
}
//添加属性
function c_AppendAttributeValue(XmlNode,attrName,attrValue){
//add_Attribute
if (XmlNode!=null) XmlNode.setAttribute(attrName,attrValue);
}
//修改属性
function c_UpdateAttributeValue(XmlNode,attrName,attrValue){
//Update_Attribute
if (XmlNode!=null) XmlNode.setAttribute(attrName,attrValue);
}
//删除属性
function c_removeAttributeValue(XmlNode,attrName,attrValue){
//remove_Attribute
if (XmlNode!=null) XmlNode.removeAttribute(attrName);
}
该博客重新编写了Java Xml Writer类的源码并开放。使用JavaScript创建Xml文档并加入Dom中,定义了clsXmlWriter类,包含创建、插入、添加、移除节点以及添加、修改、删除属性等公共成员函数,详细给出了各函数的实现代码。
745

被折叠的 条评论
为什么被折叠?



