Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(@"C:\Users\aliu16\user.xml");
            // TODO: Module[3] is ok , Module[@ID='M003'] does not work  
            XmlNode nodeModule = xmlDoc.SelectSingleNode("//UserGroup[@ID='G001']/Module[@ID='M003']"); 

who can tell me why the object 'nodeModule' is null ,but Module[3] is ok . is my xpath wrong anywhere ? thanks .

xmldocument is below :
XML
<Powers>
  <UserGroup ID="G001" Name="admin" Desc="管理员权限" Users="U001,U002,U004">
    <Module ID="MOO1" Name="UserModule" Desc="账户模块" PageUrl="" />
    <Module ID="MOO2" Name="UserModule" Desc="账户模块" PageUrl="">
      <PowerItem ID="I001" Name="UserList" Desc="用户列表浏览权限" PageUrl="~/UserList.aspx" />
      <PowerItem ID="I001" Name="UserList" Desc="用户列表浏览权限" PageUrl="~/UserList.aspx" />
    </Module>
    <Module ID="MOO3" Name="UserModule3" Desc="账户模块" PageUrl="" />
    <Module ID="MOO4" Name="UserModule" Desc="账户模块" PageUrl="" />
    <Module ID="MOO5" Name="UserModule" Desc="账户模块" PageUrl="" />
  </UserGroup>
  <UserGroup ID="G002" Name="admin2" Desc="管理员权限2" Users="U001,U004" />
</Powers>
Posted
Comments
Praveen Kumar Upadhyay 12-Dec-14 2:20am    
Module ID is MOO3 and not M003.
carono 12-Dec-14 2:30am    
omg, my mistake . thanks a lot . it works now .
Praveen Kumar Upadhyay 12-Dec-14 2:44am    
How will you close the question now?
carono 12-Dec-14 3:03am    
yes , I will . but how to close it . I'm newer here . sorry .
carono 12-Dec-14 3:04am    
to click the fork ?

1 solution

It is very small answer. You are doing a mistake.
Module ID is MOO3 and not M003.

As I have answered, So want my points:)
 
Share this answer
 
Comments
Praveen Kumar Upadhyay 12-Dec-14 3:23am    
carono, you can now accept the solution and can vote if you want.
carono 12-Dec-14 3:40am    
yes, i have accepted your solution and voted for it . thank you Praveen .
Marcin Kozub 12-Dec-14 3:33am    
Good eye, +5 :)
Praveen Kumar Upadhyay 12-Dec-14 3:35am    
Thank you Marcin
Praveen Kumar Upadhyay 12-Dec-14 3:40am    
Thank you everybody for accepting the solution and upvoting.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900