函数定义:
        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>

相关文章:

  • 2017-12-21
  • 2021-11-23
  • 2021-11-07
  • 2021-09-19
  • 2021-12-03
  • 2021-12-27
  • 2021-11-02
猜你喜欢
  • 2021-12-16
  • 2021-12-19
  • 2021-12-05
  • 2021-12-06
  • 2021-11-02
  • 2021-11-23
  • 2021-12-15
相关资源
相似解决方案