zoukankan      html  css  js  c++  java
  • 添加 XmlDocument 元素 和 属性

    函数定义:
            private XmlElement addXmlElement(XmlDocument doc, XmlElement parent, string prefix, string localName, string namespaceURI)
            {
                XmlElement elem 
    = doc.CreateElement(prefix, localName, namespaceURI);
                parent.AppendChild(elem);
                
    return elem;
            }
            
    private XmlAttribute addXmlAttribute(XmlDocument doc, XmlElement elem, string name, string val)
            {
                XmlAttribute attr 
    = doc.CreateAttribute(name);
                attr.Value 
    = val;
                elem.Attributes.Append(attr);
                
    return attr;
            }    
            
    private XmlAttribute addXmlAttribute(XmlDocument doc, XmlElement elem, string name, string val, string prefix, string ns)
            {
                XmlAttribute attr 
    = doc.CreateAttribute(prefix, name, ns);
                attr.Value 
    = val;
                elem.Attributes.Append(attr);
                
    return attr;
            }
    函数使用:
    XmlDocument doc = null;
    XmlElement config 
    = addXmlElement(doc, doc.DocumentElement, "sox""Config""Microsoft.Solutions.InformationWorker.Sox");
    XmlElement elem 
    = addXmlElement(doc, config, "sox""Taxonomy""Microsoft.Solutions.InformationWorker.Sox");
    addXmlAttribute(doc, elem, 
    "maxDepth""8");
    使用效果:
    <sox:Config>
    <sox:Components maxDepth="16">
    </sox:Components>
  • 相关阅读:
    命令实现linux和客户端文件上传下载
    python--linux上如何执行shell命令
    Eureka系列(一)Eureka功能介绍
    Eureka系列(七) 服务下线Server端具体实现
    编译时多态 与 运行时多态
    静态绑定(前期绑定) 与 动态绑定(后期绑定)
    重载 与 重写
    热点检测、方法内联、动态反优化
    数据库日志
    单例模式
  • 原文地址:https://www.cnblogs.com/xh831213/p/490216.html
Copyright © 2011-2022 走看看