欢迎来到HELLO素材网! 南京网站制作选择顺炫科技
丰富的DIV CSS模版、JS,jQuery特效免费提供下载
当前位置:主页 > 建站教程 > 网站制作教程 >

C#操作XmlDocument对象 报短少根节点

发表于2019-04-24 03:12| 次阅读| 来源网络整理| 作者session

摘要:C#操作XmlDocument对象 报短少根节点

C# 操作XmlDocument文档 1.第一步抉择文件目录 string FileName=string.Empty; SaveFileDialog sfd=new SaveFileDialog(); if(sfd.ShowDialog() == DialogResult.OK) { FileName = sfd.FileName; } FileStream fs;//判别文件能否存在 if(!File.Exists(FileName)) { fs

C#操作XmlDocument对象 报短少根节点

C# 操作XmlDocument文档

 

1.第一步抉择文件目录

 

string FileName=string.Empty;

 

SaveFileDialog sfd=new SaveFileDialog();

 

if(sfd.ShowDialog() == DialogResult.OK)

 

{

 

    FileName = sfd.FileName;

 

}

 

FileStream fs;//判别文件能否存在

 

if(!File.Exists(FileName))

 

{

 

    fs = File.Create(FileName);

 

    fs.Close();

 

}

 

2.创建文件的申明

 

XmlDocument xmlDoc = new XmlDocument();//创建Xml文件的申明

 

XmlDeclaration xmlDeclar = xmlDoc.CreateXmlDeclaration("1.0","UTF-8",null);

 

XmlElement rootElement = xmlDoc.DocumentElement;//获取文档根

 

xmlDoc.InsertBefore(xmlDeclar,rootElement);//在文档根元素之前减少申明

 

XmlElement root = xmlDoc.CreateElement("Configuration");//创建根节点

 

xmlDoc.AppendChild(root);

 

3.保存以上创建

 

xmlDoc.Save(FileName);//保存根节点之后能力向Xml文件中创建子节点

 

4.加载文件

 

xmlDoc.Load(FileName);

 

5.创建节点或元素

 

XmlElement rootNode = xmlDoc.DocumentElement;

 

rootNode.InnerText = "*****";

 

//Todo.....依据Document对象操作

 

 

 

/*****docking panel第三方组件 记载********/

分享到:

本文"C#操作XmlDocument对象 报短少根节点"由蚂蚁部落站长搜集整顿而来,仅供大家学习与参考利用。更多网站制造教程尽在蚂蚁部落站长站。

顶一下

(2)

100%

踩一下

(0)