先看看VS.Net自带帮助MSDN,详细着呢。
www.codeproject.com是不错的站点,上面例子很多。

解决方案 »

  1.   

    对啊
    建议看看msdn,市场上中文的
    他上面有“示例和演习”,讲的很好,既全面有易懂!
      

  2.   

    /// <summary>
    /// 读取XML设置
    /// </summary>
    public void ReadXml( string inTemPathName )
    {
    XmlTextReader xr=null;
    try
    {
    if(System.IO.File.Exists(inTemPathName))
    {
    xr = new XmlTextReader( inTemPathName );
    if (xr.MoveToContent() == XmlNodeType.Element && xr.Name == "System")
    {
    xr.Read();
    if (xr.MoveToContent() == XmlNodeType.Element && xr.Name == "Setup")
    {
    this.txtServer.Text = xr.GetAttribute( "DataServer" );
    this.txtDataBase.Text = xr.GetAttribute( "DataBase" );
    this.txtUser.Text = xr.GetAttribute( "User" );
    this.txtPwd.Text = xr.GetAttribute( "PassWord" );
    }
    xr.Close();
    }
    }
    }
    catch 
    {
    if ( xr != null )
    xr.Close();
    }
    }/// <summary>
    /// 生成配制文件xml
    /// </summary>
    public static void GenerateXml(string inTemPathName, string inDataServer, string inDataBase, string inUserName, string inPassWord)
    {
    XmlTextWriter xw = new XmlTextWriter( inTemPathName,System.Text.Encoding.UTF8 );
    xw.Formatting = Formatting.Indented;
    xw.IndentChar = ( char )0x9;
    xw.Indentation = 1;
    xw.WriteStartDocument();
    xw.WriteComment( "应用程序设置XML" );
    xw.WriteStartElement( "System" );
    xw.WriteStartElement( "Setup" );
    xw.WriteAttributeString( "DataServer", inDataServer);
    xw.WriteAttributeString( "DataBase", inDataBase );
    xw.WriteAttributeString( "User", inUserName );
    xw.WriteAttributeString( "PassWord", inPassWord );
    xw.WriteEndElement();
    xw.WriteEndElement();
    xw.WriteEndDocument();
    xw.Flush();
    xw.Close();
    }
      

  3.   

    刚好有一个给你了
    刚好给你
    //下面是直接用一个方法一个类来读取XML文档到树中
    private void LoadTree() 
    {     
    //Load the xml file. Change path if needed      
    doc.Load(path);

                //下面稍做修改,可以读任意根结点
    XmlTextReader xmlReader = null; xmlReader = new XmlTextReader(path); xmlReader.Read(); while(xmlReader.NodeType != XmlNodeType.Element)
    {
    xmlReader.Read();
    }            //select the root node
    XmlNode node=doc.SelectSingleNode(xmlReader.Name);
    //ijnstantaite a new XmlTreeNode,
    //fill the node 
    //load it into the TreeView
    XmlTreeNode rootNode=new XmlTreeNode(node);
    rootNode.FillTreeView();
    treeView1.Nodes.Clear();
    treeView1.Nodes.Add(rootNode); xmlReader.Close();//需要关闭 }
    internal class XmlTreeNode : TreeNode  
    {
          
    XmlNode node; internal XmlTreeNode()  : base(){} internal XmlTreeNode(XmlNode treeNode)  : base()  
    {
            
    node=treeNode;
    //Don't want the name of the node is null
    //or if the node is a text node
    if(node!=null && node.NodeType!=XmlNodeType.Text)
    this.Text=node.Name;
          
    }
          
    public string Value 
    {
    get 
    {
    if(node.HasChildNodes && node.FirstChild.NodeType==XmlNodeType.Text)
    return node.InnerText;
    return "";
    }
    } internal XmlAttributeCollection Attributes 
    {
    get 
    {
    if(node.Attributes.Count>0)
    return node.Attributes; return null;
    }
    } internal void FillTreeView() 
    { if(node!=null)  
    {
    this.Nodes.Clear();
    XmlNode cNode=node.CloneNode(true); if(cNode.HasChildNodes)  
    {
    cNode=cNode.FirstChild;
                
    while(cNode!=null)  
    {
    if(cNode.NodeType!=XmlNodeType.Text &&
    cNode.NodeType!=XmlNodeType.Attribute)  
    { XmlTreeNode newTreeNode=new XmlTreeNode(cNode);
    this.Nodes.Add(newTreeNode);
    newTreeNode.FillTreeView();
    }
    cNode=cNode.NextSibling; }
    }
    }
    }

    }
      

  4.   

    xml查询
    using System.Text;
    using System.Diagnostics;
    using System.Threading;
    using System.Collections;
    using System.Data;
    using System.Xml;
    using System.Management;
    using System.Net;
    namespace ZZ
    {
    class ZZConsole
    {
    [STAThread]
    static void Main(string[] args)
    {
    string strXml="<?xml version=\"1.0\"?>"
    +"<Data>"
    +"<Head>"
    +"<Nodeid>1111</Nodeid>"
    +"<Subid>2222</Subid>"
    +"<Version>2004</Version>"
    +"<Date>20040302</Date>"
    +"<Time>101500</Time>"
    +"</Head>"
    +"<Body>"
    +"<Code>01</Code>"
    +"<Name>深圳</Name>"
    +"<IdType>0</IdType>"
    +"<Idno>110258740824082</Idno>"
    +"</Body>"
    +"</Data>";
    XmlDocument doc = new XmlDocument();
    doc.LoadXml(strXml);
    string vv; vv = doc.GetElementsByTagName("Version")[0].InnerText;
    Console.WriteLine(vv);
    vv = doc.SelectNodes("//Version")[0].InnerText;
    Console.WriteLine(vv);
    Console.ReadLine();
    }

    }

    }
      

  5.   

    装在xml到DataSet
    using System;
    using System.Data;
    using System.Collections;
    using System.Xml;
    using System.IO;
    using System.Text;namespace ConsoleTest
    {
    /// <summary>
    /// ZZConsole 的摘要说明。
    /// </summary>
    public class ZZConsole
    {
    [STAThread]
    static void Main(string[] args)
    {

    XmlDocument xdoc= new XmlDocument();
    xdoc.Load(@"d:\test.xml");
    DataSet ds = CreatDataSet();
    XmlNodeList xList = xdoc.SelectNodes("//Item");
    foreach(XmlNode xNode in xList)
    {
    DataRow dr = ds.Tables["Items"].NewRow();
    dr["Item"] = xNode.Attributes["Name"].Value;
    ds.Tables["Items"].Rows.Add(dr);
    }
    foreach(DataRow dr in ds.Tables["Items"].Rows)
    {
    Console.WriteLine(dr["Item"].ToString());
    }
    Console.ReadLine();
    }
    public static DataSet CreatDataSet()
    {
    DataSet ds = new DataSet();
    DataTable dt = new DataTable("Items");
    DataColumn dc = new DataColumn("Item",typeof(string));
    dt.Columns.Add(dc);
    ds.Tables.Add(dt);
    return ds;
    }
    }
    }
    =======================================================
    <?xml version="1.0" encoding="utf-8" ?>
    <Root>
        <Class Name="1">
            <Item Name="Item11"/>
            <Item Name="Item12"/>
            <Item Name="Item13"/>
            <Item Name="Item14"/>
        </Class>
        <Class Name="2">
            <Item Name="Item21"/>
            <Item Name="Item22"/>
            <Item Name="Item23"/>
            <Item Name="Item24"/>
        </Class>
    </Root>
      

  6.   

    编辑xml文档
    using System;
    using System.IO;
    using System.Text;
    using System.Diagnostics;
    using System.Threading;
    using System.Collections;
    using System.Data;
    using System.Xml;
    using System.Management;
    using System.Net;
    namespace ZZ
    {
    class ZZConsole
    {
    [STAThread]
    static void Main(string[] args)
    {
    string strXml="<?xml version=\"1.0\"?>"
    +"<Data>"
    +"<Head>"
    +"<Nodeid>1111</Nodeid>"
    +"<Subid>2222</Subid>"
    +"<Version>2004</Version>"
    +"<Date>20040302</Date>"
    +"<Time>101500</Time>"
    +"</Head>"
    +"<Body>"
    +"<Code>01</Code>"
    +"<Name>深圳</Name>"
    +"<IdType>0</IdType>"
    +"<Idno>110258740824082</Idno>"
    +"</Body>"
    +"</Data>";
    XmlDocument doc = new XmlDocument();
    doc.LoadXml(strXml);
    string vv;

    XmlNodeList myNodes = doc.GetElementsByTagName("Version");
    vv = myNodes[0].InnerText;
    //修改
    myNodes[0].InnerText = "123455";
    Console.WriteLine(vv);
    myNodes = doc.SelectNodes("//Version")[0].InnerText;
    vv = myNodes[0].InnerText;
    Console.WriteLine(vv);
    //再修改
    myNodes[0].InnerText = "67890";
    doc.Save("d:\\text.xml");
    Console.ReadLine();
    }

    }

    }