asp.net 操作xml文件
using System.Xml;//头部加此命名空间
XmlDocument xd = new XmlDocument();//表示XML文档
XmlDeclaration xde;//表示 XML 声明节点:<?xml version='1.0'...?>
xde = xd.CreateXmlDeclaration("1.0", "GBK", null);//参数的第二项为编码方式
//standalone定义了是否可以在不读取任何其它文件的情况下处理该文档,默认为no
xd.AppendChild(xde);//<?xml version="1.0" encoding="UTF-8" standalone="yes"?>生成结束
XmlElement xe = xd.CreateElement("Root");//创建一个Root根元素
xd.AppendChild(xe);//Root根元素创建完成
XmlNode root = xd.SelectSingleNode("Root");//查找<Root>
XmlElement xe1 = xd.CreateElement("Tree");//在<Root>之下创建元素<Tree>
xe1.SetAttribute("id","1");//指定属性的属性值
xe1.InnerText = "类型1";//指定属性文本节点
root.AppendChild(xe1);//完成子节点<Tree>
xd.Save(Server.MapPath("xml.xml"));
下面的内容我暂时没有使用到: 有一些错误,都是双引号的问题,有的需要在名称两边加双引号才能正常使用.
已知有一个XML文件(bookstore.xml)如下:
<?xml version=1.0 encoding=gb2312?>
<bookstore>
<book genre=fantasy ISBN=2-3631-4>
<title>Oberon's Legacy</title>
<author>Corets, Eva</author>
<price>5.95</price>
</book>
</bookstore>
1、往<bookstore>节点中插入一个<book>节点:
XmlDocument xmlDoc=new XmlDocument();
xmlDoc.Load(bookstore.xm
相关文档:
1.连接数据库文件
<add name="LocalSqlServer" connectionString="Data Source=.\SQLExpress;Integrated Security=True;AttachDBFilename=|DataDirectory|TimeTracker.mdf;User Instance=true" />
SqlConnectionStringBuilder实例化时,要用到connectionString,如:SqlConnectionStringBuild builder = new SqlC ......
标签:数据访问 LINQ to XML
LINQ to XML并不打算替代标准的XML API,只是补充了这些标准XML类 ......
标签:数据访问 ADO.NET
通过LINQ to XML生成 XML XML常常用语在客户机和服务器之间交流数据,或者多层应用程序之间交流。
用LINQ to SQL查询数据,再用LI ......
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
namespace System.Bwch.XmlConfig
{
/**////
/// 读取XML配置文件类
///
public class XmlHelper
{
private string strXmlPath = ""; //Xml文档路径
private XmlDocument xmlD ......
ASP.NET 页运行时,此页将经历一个生命周期,在生命周期中将执行一系列处理步骤。这些步骤包括初始化、实例化控件、还原和维护状态、运行事件处理程序代码以及进行呈现。了解页的生命周期非常重要,这样就能在合适的生命周期阶段编写代码,以达到预期效果。此外,如果开发自定义控件,则必须熟悉页生命周期,从而正确地初始 ......