1.怎么创建
2.怎么把"123"这个字符串存进去
3.怎么把"123"读取出来
4.怎么遍历所有存进去的字符串
5.能不能存入Bitmap等..
谢谢
2.怎么把"123"这个字符串存进去
3.怎么把"123"读取出来
4.怎么遍历所有存进去的字符串
5.能不能存入Bitmap等..
谢谢
解决方案 »
- C#调用C++就那么难吗?调用接口有结构体!怎么测试都得不到正确结果。
- c#里要枚举工作组下的所有计算机的函数是那个?
- 请教AJAX后台代码C#的
- datagrid的简单问题
- TreeView控件的图片功能怎么用?
- CLR创建触发器问题(能否在触发器加入Oledbconnect连接)
- 这个方法被调用一次 自己却执行两次(求指点,得永生啊~)
- C# 新手向 错误 CS0103: 当前上下文中不存在名称“ticks”
- 高手好?~~请问我怎么读txt.txt里面的东西
- 关于报表控件 fastreport
- C# 用户自定义控件添加时出现意想不到结果 请多多指教
- 正则式有关问题:这个正则式前面的(?m)什么含义
2,3面太广,没法回答
4,LINQ TO XML或将xml读入数据集然后遍历
5,不明白什么意思
XmlNode root =doc.CreateElement("Setting");
C# 建立xml文件的方法
string xmlFile = System.Windows.Forms.Application.StartupPath + "\\system.xml"; XmlDocument xml = new XmlDocument(); //建立XmlDomcument对象
XmlDeclaration Declaration = xml.CreateXmlDeclaration("1.0", "utf-8", null); //Xml Declaration(Xml声明)
XmlNode RootNode = xml.CreateNode(XmlNodeType.Element, "", "ROOT", "");
xml.AppendChild(RootNode); XmlNode node1 = xml.CreateNode(XmlNodeType.Element, "", "频率范围", "");
node1.Attributes.Append(xml.CreateAttribute("VALUE")).InnerText = 123;
xml.InsertBefore(Declaration, xml.DocumentElement);
try
{
xml.Normalize();
xml.Save(xmlFile);
}
catch (Exception ex)
{
// 显示错误信息
MessageBox.Show("保存xml文件出错:" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
读: XmlDocument xml = new XmlDocument();
if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\system.xml"))
{
xml.Load(System.Windows.Forms.Application.StartupPath + "\\system.xml");
XmlNode root = xml.DocumentElement;//读取XML的根节点
foreach (XmlNode node in root.ChildNodes)//对子节点进行循环
{
if (node.HasChildNodes)
{
string str = wavecomboBox.Text.Substring(0, wavecomboBox.Text.Length - 2);
if (node.Attributes["VALUE"].Value == str)
{
foreach (XmlNode childnode in node.ChildNodes)
{
if (childnode.Name == "霍尔")
{
choicehall = int.Parse(childnode.InnerText);
}
else if (childnode.Name == "温度")
{
choiceTemp = int.Parse(childnode.InnerText) * 10;
}
else if (childnode.Name == "LT")
{
choiceLTVolt = int.Parse(childnode.InnerText);
}
}
}
}
}
}
else
{
MessageBox.Show("配置文件未找到,请确认程序文件夹下是否存在“System.xml”这个文件", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
<student>
<name>jack</name>
<age>22</age>
<name>rose</name>
<age>21</age>
</student>
读取:
要想操作XML文件,需要引入System.XML命名空间1、实例化XmlDocument对象,该对象可标识整个XML文档
2、利用它的Load()方法将指定的XML文档加载如该XmlDocument对象
3、获取该文档的根节点 节点对象为XmlNode
4、遍历循环其下子节点
XmlDocument myxml = new XmlDocument();
myxml.Load("指定XML文件");
XmlNode node = myxml.DocumentElement;foreach(XmlNode demoNode in node.ChildNodes)
{
switch(demoNode.Name)
{ //执行代码
}
}