<?xml version="1.0" encoding="utf-8"?> 
<CRM_Dictionary>  
<Service_Score> 
    <sort>3</sort> 
    <default>false</default> 
    <enalbe>false</enalbe> 
    <content>东北区</content> 
  </Service_Score> 
  <Client_Area> 
    <sort>0 </sort> 
    <default_>false </default_> 
    <enable>false </enable> 
    <content>sdfad </content> 
  </Client_Area> 
  <Client_Area> 
    <sort>1 </sort> 
    <default_>false </default_> 
    <enable>true </enable> 
    <content>asdfsad </content> 
  </Client_Area> 
  <Client_Area> 
    <sort>2 </sort> 
    <default_>false </default_> 
    <enable>false </enable> 
    <content>asdfasd </content> 
  </Client_Area> 
  <Client_Area> 
    <sort>3 </sort> 
    <default_>true </default_> 
    <enable>false </enable> 
    <content>3434343434 </content> 
  </Client_Area> 
</CRM_Dictionary>    ---这是我的xml 我如何用vs2008 获取所有节点Client_Area的值

解决方案 »

  1.   

    你又用dom
    创建一个dom
    上网查查
    网上比较多
      

  2.   

      XElement doc = XElement.Load("tt.xml");
                var v = from s in doc.Descendants("Client_Area")
                        select s.Value;
                foreach(string s in v)
                {
                    Console.WriteLine(s);
                }用linq to xml 来实现
    引入命名空间using System.Xml.Linq;
      

  3.   

    <%
    Set oDoc    = CreateObject("Msxml2.DOMDocument")
    With oDoc
        .async              = False
        .validateOnParse    = False
        .preserveWhiteSpace = False
        .resolveExternals   = False
        .load "c:\xxx.xml"
        If .parseError.errorCode <> 0 Then
            sErrMsg     = .parseError.errorCode & "|" &_
                          .parseError.srcText & "|" & .parseError.reason
            Err.Raise 62002, "Create", sErrMsg
        End If
        Set oNodes = .selectNodes("//Client_Area")
        For i=0 To oNodes.length-1
           Set oNode = oNodes(i).selectSingleNode("sort")
           Response.Write oNode.text
           Set oNode = oNodes(i).selectSingleNode("default_")
           Response.Write oNode.text
           Set oNode = oNodes(i).selectSingleNode("enable")
           Response.Write oNode.text
           Set oNode = oNodes(i).selectSingleNode("content")
           Response.Write oNode.text
        Next
    End With
    %>
    这是一位牛哥用asp给我发的,可我好象用C#弄不了,有哪位牛哥把这个改成C#的
      

  4.   


    这个using System.Xml.Linq;我放在程序里报错,说这个命名空间不存在
      

  5.   

    ling 需要framework3.5的支持
    你不是用vs2008建的项目吗?难道没有还是用的framework2.0
      

  6.   

    大哥
    from s in myDoc.Descendants("Client_Area")
    这里的Descendants这个过不去
      

  7.   

    引入了大哥
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using ZoomLa.Model;
    using ZoomLa.BLL;
    using ZoomLa.Common;
    using System.Xml;
    using System.IO;
    using System.Xml.Linq;
    using System.Xml.Schema;
    using System.Xml.XPath;
    using System.Xml.Xsl;
    public partial class manage_AddCRM_CRMDictionary : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
                   if (!IsPostBack) {
                labe = repeater1.Items.Count;            var v = from s in myDoc.Descendants("Client_Area")
                        select s.Value;
                foreach (string s in v)
                {
                    Console.WriteLine(s);
                }
            }
        }
    }
      

  8.   

    using System.Xml; 
    using System.IO; 
    using System.Xml.Linq; 
    using System.Xml.Schema; 
    using System.Xml.XPath; 
    using System.Xml.Xsl; 
    public partial class manage_AddCRM_CRMDictionary : System.Web.UI.Page 

        protected void Page_Load(object sender, EventArgs e) 
        {  
            if (!IsPostBack) { 
               XElement doc = XElement.Load("tt.xml"); 
                var v = from s in myDoc.Descendants("Client_Area") 
                        select s.Value; 
                foreach (string s in v) 
                { 
                    Console.WriteLine(s); 
                } 
            } 
        } 
    }这个过不去啊!!!
      

  9.   

    XElement doc = XElement.Load("tt.xml"); //你需要加载xml文件
      

  10.   

        public manage_AddCRM_CRMDictionary()
        {
            //构造函数
            myDoc = new XmlDocument();
            myDoc.Load(Server.MapPath("../../Config/CRM_Dictionary.xml"));
        }
    我在构造时就加了
      

  11.   

    不要用XmlDocument,是XElement 
      

  12.   

    using System.Xml; 
    using System.IO; 
    using System.Xml.Linq; 
    using System.Xml.Schema; 
    using System.Xml.XPath; 
    using System.Xml.Xsl;  
      protected void Page_Load(object sender, EventArgs e)
        {    
            if (!IsPostBack) {
                labe = repeater1.Items.Count;
                XDocument xmlFile = XDocument.Load("../../Config/CRM_Dictionary.xml");
                var query = from c in xmlFile.Elements("CRM_Dictionary").Elements("sort")
                            select c;
                foreach (XElement book in query)
                {
                    Console.WriteLine(book.Value.ToString());
                } 
            }
        }这样还是不行,!!!
      

  13.   

    你想要什么样的结果???
    我晕。我给你的代码不是这个样子的啊
    var v = from s in doc.Descendants("Client_Area")
                        select s;
                foreach(string s in v)
                {
                    Console.WriteLine(s);
                }
      

  14.   

    using System.Xml; 
    using System.IO; 
    using System.Xml.Linq; 
    using System.Xml.Schema; 
    using System.Xml.XPath; 
    using System.Xml.Xsl;    
      protected void Page_Load(object sender, EventArgs e)
        {     
            if (!IsPostBack) {
                XElement doc = XElement.Load("../../Config/CRM_Dictionary.xml");
                var v = from s in doc.Descendants("Client_Area")
                        select s.Value;
                foreach (string s in v)
                {
                    Console.WriteLine(s);
                } 
            }
        }
    报:当前上下文不存在  XElement 
      

  15.   

    你的是web的项目吧。请在Load的地方用 XElement.Load(Server.MapPath("~/Config/CRM_Dictionary.xml"));
      

  16.   

    是,还是不行!!!
    谢大哥你了,我找下别的方法,
    用XmlDocument
      

  17.   

    这是C#3.0的LINQ
    如果你VS不支持的话,先添加System.Xml.Linq程序集的引用,然后再添加using System.Xml.Linq; 
    没有这个上面那个DLL可以下个,呵呵