<?xml version="1.0" encoding="UTF-8"?>
<sqlMap namespace="UserInfo" xmlns="http://ibatis.apache.org/mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
  <alias>
    <typeAlias alias="userinfo" type="FinancialSystem.To.UserInfo, FinancialSystem.To"></typeAlias>
  </alias>
 <update id="UpdateUserPassword"  parameterClass="userinfo" >
      UPDATE FS_UserInfo SET
      UserPassword=#UserPassword#
      WHERE
      UserId = #UserId#
    </update>
    <!--================ End ========================== -->    <!-- ============================================== -->
    
     <!-- ==============Update statement================== -->
    <update id="UpdateUserRight"  parameterClass="userinfo" >
      UPDATE FS_UserInfo SET
          UserRight=#UserRight#
      WHERE
        UserId = #UserId#
    </update></sqlMap>
怎样通过ID读取update中的内容,找了些方法也没成功,高手们帮帮忙,谢谢了!!

解决方案 »

  1.   

    XmlDocument
    XmlNode
    XmlElement
      

  2.   

    System.Xml.XmlDataDocument   dom   =   new   System.Xml.XmlDataDocument(); 
      dom.Load(Server.MapPath( ". ")   +   XML_FILE_NAME) 
                            System.Xml.XmlNodeList   list   =   dom.SelectNodes( "xpath "); 
                            
                            foreach   (System.Xml.XmlNode   node   in   list) 
                            { 
                                    xxxxxx 
                            } 
      

  3.   

    XmlDocument加载xml文档xml.SelectSingleNode(@"//update[@id='你的ID']");
    使用xpath获取node
      

  4.   

    注意你的命名空间   System.Xml.XmlDocument _Documnet = new System.Xml.XmlDocument();
                _Documnet.LoadXML(@"?????????");            XmlNamespaceManager _NameSpace = new XmlNamespaceManager(_Documnet.NameTable);
           
                _NameSpace.AddNamespace("Mo", _Documnet.ChildNodes[1].NamespaceURI);       
                System.Xml.XmlNodeList _List = _Documnet.SelectNodes("Mo:sqlMap/Mo:update[@id='UpdateUserRight']", _NameSpace);  
      

  5.   

    转化成XmlDocment,取得XmlElement,想怎样改都没问题的!
      

  6.   

    System.Xml.XmlNodeList xnList = myXML.SelectNodes(@"//update[@id='UpdateUserRight']");            foreach (System.Xml.XmlNode xn in xnList)
                {
                    str = xn.InnerText;
                }
    这样也读出来是空的
      

  7.   


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Xml;namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            { 
                string xml = @"<?xml version='1.0' encoding='UTF-8'?> 
                <sqlMap namespace='UserInfo' xmlns='http://ibatis.apache.org/mapping' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' > 
                  <alias> 
                    <typeAlias alias='userinfo' type='FinancialSystem.To.UserInfo, FinancialSystem.To'> </typeAlias>
                  </alias> 
                <update id='UpdateUserPassword'  parameterClass='userinfo' > 
                      UPDATE FS_UserInfo SET 
                      UserPassword=#UserPassword# 
                      WHERE 
                      UserId = #UserId# 
                    </update> 
                    <update id='UpdateUserRight'  parameterClass='userinfo' > 
                      UPDATE FS_UserInfo SET 
                          UserRight=#UserRight# 
                      WHERE 
                        UserId = #UserId# 
                    </update>             </sqlMap> ";            XmlDocument doc=new XmlDocument();            doc.LoadXml(xml);            XmlNamespaceManager ns = new XmlNamespaceManager(doc.NameTable);            ns.AddNamespace("Mo", doc.ChildNodes[1].NamespaceURI);            System.Xml.XmlNode node = doc.SelectSingleNode("Mo:sqlMap/Mo:update[@id='UpdateUserRight']", ns);            Console.Write("{0}", node.ChildNodes[0].Value );
                /*
                 
                      UPDATE FS_UserInfo SET
                          UserRight=#UserRight#
                      WHERE
                        UserId = #UserId#             */
                Console.ReadKey();
            }}
      

  8.   

    关键是表达式要写正确
    提一点容易混淆的
    先来个示例文本:
    <test>
    <node name="def">
    <name>abc</name>
    </node>
    </test>
     值为def的name是node的属性, 值为abc的name是node的子节点
    前者的Xpath写法:/test/node[@name='def'],
    后者的Xpath写法:/test/node[name='abc']
    区别在有没有那个@符号,如果有,代表节点的属性,如果没有,代表子节点
    xpath的一般格式:
    用个/打头,然后 是根节点,再然后是子节点,中间用/隔开,(注意最后没有/)
    另外可以用XML命名空间的表达式,比较烦琐,不用
      

  9.   


    这样写是没有问题的,可是用XML.Load("E:\\WorkProjects\\WebApplication1\\WebApplication1\\UserInfo.xml")不知道为什么就读不出数据
      

  10.   

                string xml = @"F:\Test.xml";            XmlDocument doc=new XmlDocument();            doc.Load(xml);
    我这样写没问题
      

  11.   

    /// <summary>
            /// 节点查询,返回节点值
            /// </summary>
            /// <param name="XmlPathNode">节点的路径</param>
            /// <returns></returns>
            public string SelectNodeText(string XmlPathNode)
            {
                string _nodeTxt = XmlDoc.SelectSingleNode(XmlPathNode).InnerText;
                if (_nodeTxt == null || _nodeTxt == "")
                    return "";
                else
                    return _nodeTxt;
            }(@"//update[@id='你的ID'
    string _delNode = "//Root/Student[Name='" + _delName + "']";
    string ss = "//update[@id='id值']";
            string _photo = SelectNodeText(ss);
      

  12.   


    XmlDocument xml = new XmlDocument();
                xml.Load(strPath);
                XmlNode xl = xml.SelectSingleNode("sqlMap/update[@Id=2]");
                if (xl != null)
                {
                    Console.WriteLine(xl.ChildNodes[0].InnerText);
                    //if (xl.Attributes.Count > 2)
                    //    Console.WriteLine(xl.Attributes["Description"].InnerText);
                }
      

  13.   


    XmlDocument xml = new XmlDocument();
                xml.Load(strPath);
                XmlNode xl = xml.SelectSingleNode("sqlMap/update[@id=UpdateUserRight]");
                if (xl != null)
                {
                    Console.WriteLine(xl.ChildNodes[0].InnerText);
                }
      

  14.   

    string xml = @"E:\WorkProjects\WebApplication1\WebApplication1\Test.xml";
                XmlDocument doc = new XmlDocument();            doc.Load(xml);
    XmlNode xl = doc.SelectSingleNode("sqlMap/update[@id=UpdateUserRight]");
    这句执行后xl是空的,doc里面是有值的
      

  15.   

    XmlNode xl = doc.SelectSingleNode("sqlMap/update[@id=UpdateUserRight]"); 
    Xpath表达式错误我的回贴你都没认真看,如果你看懂了就OK了
      

  16.   

    XmlDocument xmlDoc=new XmlDocument();
                xmlDoc.Load(xmlPath);//xml路径
                XmlNode aa = xmlDoc.SelectSingleNode("sqlMap");
                XmlNodeList nodeList = aa.ChildNodes;//获取sqlMap节点的所有子节点
                foreach(XmlNode xn in nodeList)//遍历所有子节点
                {
                    XmlElement xe=(XmlElement)xn;//将子节点类型转换为XmlElement类型
                    if (xe.GetAttribute("id") == "UpdateUserPassword")//查找ID为:UpdateUserPassword的节点
                    {
                         MessageBox.Show(xe.InnerText);//输出节点间的数据
                    }
                }            xmlDoc.Save(xmlPath);//保存。
      

  17.   

    你确定Test.xml就是
    <?xml version="1.0" encoding="UTF-8"?>
    <sqlMap namespace="UserInfo" xmlns="http://ibatis.apache.org/mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
      <alias>
        <typeAlias alias="userinfo" type="FinancialSystem.To.UserInfo, FinancialSystem.To"> </typeAlias>
      </alias>
    <update id="UpdateUserPassword"  parameterClass="userinfo" >
          UPDATE FS_UserInfo SET
          UserPassword=#UserPassword#
          WHERE
          UserId = #UserId#
        </update>
        <!--================ End ========================== -->    <!-- ============================================== -->
       
        <!-- ==============Update statement================== -->
        <update id="UpdateUserRight"  parameterClass="userinfo" >
          UPDATE FS_UserInfo SET
              UserRight=#UserRight#
          WHERE
            UserId = #UserId#
        </update></sqlMap> xmlPath是区分大小写的。
      

  18.   


     using (StreamWriter sw = new StreamWriter(strPath,false))
                {
                    sw.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
                    sw.WriteLine("<sqlMap>");
                    sw.WriteLine("<update Id=\"2\" EditViewName=\"EditView\" Description=\"杨浦区\">");
                    sw.WriteLine("Hello from the boy who is working is BeiJing as a coder.");
                    sw.WriteLine("</update>");
                    sw.WriteLine("<update Id=\"3\" EditViewName=\"EditViewBanBiDian\" Description=\"普陀区\">");
                    sw.WriteLine("</update>");
                    sw.WriteLine("</sqlMap>");
                    sw.Flush();
                }
                //XmlPath的应用
                XmlDocument xml = new XmlDocument();
                xml.Load(strPath);
                XmlNode xl = xml.SelectSingleNode("sqlMap/update[@Id=2]");
                if (xl != null)
                {
                    Console.WriteLine(xl.ChildNodes[0].InnerText);
                    //if (xl.Attributes.Count > 2)
                    //    Console.WriteLine(xl.Attributes["Description"].InnerText);
                }你自己跑一遍看看..