XmlDocument的应用创建Xml模板

摘要:
xmlversion=“1.0”encoding=“utf-8”?
XmlDocument的应用创建Xml模板第1张 protected void btnCreate_Click(object sender, EventArgs e)
XmlDocument的应用创建Xml模板第2张XmlDocument的应用创建Xml模板第3张        
XmlDocument的应用创建Xml模板第4张{
XmlDocument的应用创建Xml模板第5张            
//定义XMLDocument
XmlDocument的应用创建Xml模板第5张
            XmlDocument xmlDocument = new XmlDocument();
XmlDocument的应用创建Xml模板第5张
XmlDocument的应用创建Xml模板第5张            
//定义XML文档头文件
XmlDocument的应用创建Xml模板第5张
            XmlDeclaration xmlDeclaration = xmlDocument.CreateXmlDeclaration("1.0""utf-8"null);
XmlDocument的应用创建Xml模板第5张            
//增加XML文档头
XmlDocument的应用创建Xml模板第5张
            xmlDocument.AppendChild(xmlDeclaration);
XmlDocument的应用创建Xml模板第5张
XmlDocument的应用创建Xml模板第5张            
//定义XML的根
XmlDocument的应用创建Xml模板第5张
            XmlElement xmlRoot = xmlDocument.CreateElement("Roots");
XmlDocument的应用创建Xml模板第5张            
//添加XML的根
XmlDocument的应用创建Xml模板第5张
            xmlDocument.AppendChild(xmlRoot);
XmlDocument的应用创建Xml模板第5张
XmlDocument的应用创建Xml模板第5张            
//添加根的属性
XmlDocument的应用创建Xml模板第5张
            xmlRoot.SetAttribute("RootAttribute""Value");
XmlDocument的应用创建Xml模板第5张
XmlDocument的应用创建Xml模板第5张            
//修改根属性的值
XmlDocument的应用创建Xml模板第5张
            xmlRoot.GetAttributeNode("RootAttribute").Value = "FixValue";
XmlDocument的应用创建Xml模板第5张
XmlDocument的应用创建Xml模板第5张            
//定义节点
XmlDocument的应用创建Xml模板第5张
            XmlNode xmlElement;
XmlDocument的应用创建Xml模板第5张
XmlDocument的应用创建Xml模板第5张            
//循环创建节点
XmlDocument的应用创建Xml模板第5张
            for (int i = 0; i < 2; i++)
XmlDocument的应用创建Xml模板第29张XmlDocument的应用创建Xml模板第30张            
XmlDocument的应用创建Xml模板第4张{
XmlDocument的应用创建Xml模板第5张                
//创建XML根的节点
XmlDocument的应用创建Xml模板第5张
                xmlElement = xmlDocument.CreateElement("Element");
XmlDocument的应用创建Xml模板第5张
XmlDocument的应用创建Xml模板第5张                
//XML需要的属性列表
XmlDocument的应用创建Xml模板第5张
                foreach (KeyValuePair<String, String> keyValuePair in NameValueDictionary())
XmlDocument的应用创建Xml模板第29张XmlDocument的应用创建Xml模板第30张                
XmlDocument的应用创建Xml模板第4张{
XmlDocument的应用创建Xml模板第5张                    
//定义XML根的节点中的属性
XmlDocument的应用创建Xml模板第5张
                    XmlAttribute oneAttribute = xmlDocument.CreateAttribute(keyValuePair.Key);
XmlDocument的应用创建Xml模板第5张                    oneAttribute.Value 
= keyValuePair.Value;
XmlDocument的应用创建Xml模板第5张
XmlDocument的应用创建Xml模板第5张                    XmlAttribute secAttribute 
= xmlDocument.CreateAttribute(keyValuePair.Key);
XmlDocument的应用创建Xml模板第5张                    secAttribute.Value 
= keyValuePair.Value;
XmlDocument的应用创建Xml模板第5张
XmlDocument的应用创建Xml模板第5张                    
//添加XML根的节点中的属性
XmlDocument的应用创建Xml模板第5张
                    xmlElement.Attributes.Append(oneAttribute);
XmlDocument的应用创建Xml模板第5张                    xmlElement.Attributes.Append(secAttribute);
XmlDocument的应用创建Xml模板第5张
XmlDocument的应用创建Xml模板第5张                    
//添加XML根的节点
XmlDocument的应用创建Xml模板第5张
                    xmlRoot.AppendChild(xmlElement);
XmlDocument的应用创建Xml模板第53张                }

XmlDocument的应用创建Xml模板第53张            }

XmlDocument的应用创建Xml模板第5张            
//保存XML文档
XmlDocument的应用创建Xml模板第5张
            xmlDocument.Save(Server.MapPath("OutDocument.XML"));
XmlDocument的应用创建Xml模板第57张        }

XmlDocument的应用创建Xml模板第1张
XmlDocument的应用创建Xml模板第1张        
//XML需要的属性列表
XmlDocument的应用创建Xml模板第1张
        private Dictionary<String, String> NameValueDictionary()
XmlDocument的应用创建Xml模板第2张XmlDocument的应用创建Xml模板第3张        
XmlDocument的应用创建Xml模板第4张{
XmlDocument的应用创建Xml模板第5张            Dictionary
<String, String> nameValueDictionary = new Dictionary<String, String>();
XmlDocument的应用创建Xml模板第5张
XmlDocument的应用创建Xml模板第5张            nameValueDictionary.Add(
"AttributeOne""One");
XmlDocument的应用创建Xml模板第5张            nameValueDictionary.Add(
"AttributeSec""Second");
XmlDocument的应用创建Xml模板第5张
XmlDocument的应用创建Xml模板第5张            
return nameValueDictionary;
XmlDocument的应用创建Xml模板第57张        }

XmlDocument的应用创建Xml模板第1张生成的XML模块
XmlDocument的应用创建Xml模板第1张
XmlDocument的应用创建Xml模板第1张
<?xml version="1.0" encoding="utf-8"?>
XmlDocument的应用创建Xml模板第1张
<Roots RootAttribute="FixValue">
XmlDocument的应用创建Xml模板第1张  
<Element AttributeOne="One" AttributeSec="Second" />
XmlDocument的应用创建Xml模板第1张  
<Element AttributeOne="One" AttributeSec="Second" />
XmlDocument的应用创建Xml模板第1张
</Roots>

免责声明:文章转载自《XmlDocument的应用创建Xml模板》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇uniapp 上下左右手势滑动时的事件Laravel Repository 模式下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Java基于自定义注解的面向切面的实现

目的:实现在任何想要切的地方添加一个注解就能实现面向切面编程 自定义注解类 @Target({ElementType.PARAMETER, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) public @interface LongOu { } @Target,...

关于WinForm/Web如何使用缓存Cach

Cache 的绝对到期与滑动到期 绝对到期:设置绝对过期时间 到了指定时间以后会失效。(类似Cookie机制) 相对到期也称滑动到期:设置相对过期时间 指定时间内无访问会失效。(类似Session机制) HttpRuntime.Cache与HttpContext.Current.Cache 为同一个对象HttpRuntime.Cache.Add 存在相同...

activiti流程动态创建

前言: 这些天由于一直在设计新系统的数据库表,导致了activiti的迟迟更新,原本之前是打算先分享下监听器的。结果被工作耽搁了,期间正好了解到新系统有这样的一个功能,流程的动态创建,即用户在前端界面选择任务节点,后台生成流程实例。参考了下网上的资料,再改了改,最终也实现了,觉得可用性还是挺大的,所以先来分享一下吧。 先附上参考链接吧,毕竟也得尊重下别人的...

JDBC之查询

案例1:查询所有用户的信息,封装到一个List里面 1 String url="jdbc:mysql://localhost:3306/nz201"; 2 String user="root"; 3 String password="root"; 4 5 Connection...

[Google Guava]学习--新集合类型Multimap

每个有经验的Java程序员都在某处实现过Map<K, List<V>>或Map<K, Set<V>>,并且要忍受这个结构的笨拙。 假如目前有个需求是给两个年级添加5个学生,并且统计出一年级学生的信息: public classMultimapTest { classStudent {...

Unicode基本概念

Unicode是计算机可以支持这个星球上多种语言的秘密武器。通过使用一个或者多个字节来表示一个字符的方法突破了ASCII的限制。Unicode可以表示超过90000个字符。 使用方式:a=u'hello' #Unicode String String的内建函数str()和chr()并没有升级来处理Unicode,新的内建函数unicode()和unichar...