加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

C# -- 使用XmlDocument或XDocument创建xml文件

发布时间:2020-12-15 04:44:58 所属栏目:百科 来源:网络整理
导读:使用XmlDocument或XDocument创建xml文件 需引用:System.Xml; System.Xml.Linq; 1.使用XmlDocument创建xml(入门案例) Main( XmlDocument xmldoc = XmlDeclaration xmldec = xmldoc.CreateXmlDeclaration( , , XmlElement rootElement = xmldoc.CreateEleme

使用XmlDocument或XDocument创建xml文件

需引用:System.Xml; System.Xml.Linq;

1.使用XmlDocument创建xml(入门案例)

Main( XmlDocument xmldoc = XmlDeclaration xmldec = xmldoc.CreateXmlDeclaration(,, XmlElement rootElement = xmldoc.CreateElement( XmlElement classElement = xmldoc.CreateElement( XmlAttribute atrrClass = xmldoc.CreateAttribute( atrrClass.Value = XmlElement stuElement = xmldoc.CreateElement( XmlAttribute attrStu = xmldoc.CreateAttribute( attrStu.Value = xmldoc.Save( Console.WriteLine( }

使用XmlDocument创建的xml文件:

2. 使用XDocument创建xml(入门案例)

Main( System.Xml.Linq.XDocument xdoc = XDeclaration xdec = XDeclaration(, xdoc.Declaration = XElement rootEle = XElement( XElement classEle = XElement( XAttribute attrClass = XAttribute(, XElement stuEle = XElement( XAttribute atrStu = XAttribute(, xdoc.Save( Console.WriteLine( }

使用XDocument创建的Xml文件:

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读