<PCCData>
<PCC Type="必修课" ISBN="7-111-19149-5">
<PCCName >
PCC
</PCCName>
<ConnectionName>
192.168.1.1
</ConnectionName>
<SQLData>
PCC
</SQLData>
<SQLType>
SQL
</SQLType>
<SQLName>
sa
</SQLName>
<SQLPassWord>
sa
</SQLPassWord>
</PCC>
<PCC Type="必修课" ISBN="7-111-19149-4">
<PCCName>
PCCSQL
</PCCName>
<ConnectionName>
192.168.1.1
</ConnectionName>
<SQLData>
PCC
</SQLData>
<SQLType>
SQL
</SQLType>
<SQLName>
sa
</SQLName>
<SQLPassWord>
sa
</SQLPassWord>
</PCC>
</PCCData>
#region 全局变量 //调用XML XmlDocument XmlDoc = new XmlDocument(); #endregion public UserTableSelectXml() { InitializeComponent(); //湖区xml文件 XmlDoc.Load(@"../../XML/UserAddDelectUpdate.xml"); //1.获取到xml的根节点 XmlNode XNode = XmlDoc.SelectSingleNode("UserTableXml//UserTable"); //2.获取根节点下的直接点 XmlNodeList XNodeList = XNode.ChildNodes; //实例 集合UserTableModel的集合 List<UserTableModel> UserTableModelList = new List<UserTableModel>(); //3.根据直接点直接回去值,根据节点名称 foreach (XmlNode Xnode in XNodeList) { UserTableModel UserTbael = new UserTableModel(); //得到UserTable节点的所有子节点 UserTbael.UserID = int.Parse(Xnode["UserID"].InnerText); UserTbael.UserName = Xnode["UserName"].InnerText; UserTbael.UserAge = int.Parse(Xnode["UserAge"].InnerText); UserTableModelList.Add(UserTbael); } UserTableSelect.DataContext = UserTableModelList; }