c# xml API操作

            LoginInfo loginInfo = new LoginInfo();
            xmlNode = _xml.SelectSingleNode(loginUrl);
            loginInfo.LoginUrl = xmlNode.InnerText;
            xmlNode = _xml.SelectSingleNode(loginUser);
            loginInfo.UserId = xmlNode.Attributes["tagId"].Value;
            loginInfo.UserValue = xmlNode.InnerText;
            xmlNode = _xml.SelectSingleNode(loginPwd);
            loginInfo.PwdId = xmlNode.Attributes["tagId"].Value;
            loginInfo.PwdValue = xmlNode.InnerText;
            xmlNode = _xml.SelectSingleNode(loginBtnId);
            loginInfo.BtnId = xmlNode.InnerText;
XML:
    <login>
      <url>http://1xxx.com/JLxxxxn/Lxxxxx.aspx</url>
      <user tagId="txtAccount">xxxx</user>
      <pwd tagId="txtPassword">xxxxx</pwd>
      <btnId>btnLogin</btnId>
    </login>

取节点中间的值使用xmlNode.InnerText,即使用InnerText属性。如<btnId>btnLogin</btnId>

取属性的值可以使用xmlNode.Attributes["tagId"].Value,即使用属性的Value属性,如<user tagId="txtAccount">xxxx</user> 的tagId属性

posted @ 2013-12-19 18:44  沧海一滴  阅读(962)  评论(0编辑  收藏  举报