JavaScript Xml Writer Class

该博客重新编写了Java Xml Writer类的源码并开放。使用JavaScript创建Xml文档并加入Dom中,定义了clsXmlWriter类,包含创建、插入、添加、移除节点以及添加、修改、删除属性等公共成员函数,详细给出了各函数的实现代码。

//以前写过的,现在重新写了一下,源码开放,使用的人请将扩充项回帖,谢谢

 /*
  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);
 }

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值