c# - Linq to xml query not returning any values -


i'm pulling xml list of sharepoint site collection users , trying query innerxml. innerxml looks this:

<users xmlns="http://schemas.microsoft.com/sharepoint/soap/directory/">  <user id="91" name="jane smith" loginname="domain1\jsmith" /> <user id="814" name="brad jones" loginname="domain1\bjones" /> <user id="1252" name="charles johnson" loginname="domain2\cjohnson" /> </users> 

query not returning (el null), though there user id 814.

xmlnode siteusers = tempug.getusercollectionfromsite(); xelement root = xelement.parse(siteusers.innerxml);     ienumerable<xelement> siteuserselement =         el in root.elements("user")         (string)el.attribute("id") == "814"         select el; foreach (xelement el in siteuserselement) console.writeline("el: " + el); 

root contains innerxml text, don't think problem has sharepoint.

you're not specifying namespace in elements call. fortunately easy in linq xml:

xnamespace ns = "http://schemas.microsoft.com/sharepoint/soap/directory/"; ... el in root.elements(ns + "user"); 

if know id attribute integer, i'd make clear, , avoid using query expression when doesn't you:

// todo: find nicer way of doing this; shouldn't need parse again xelement root = xelement.parse(siteusers.innerxml); var siteuserelements = root.elements(ns + "user")                            .where(el => (int) el.attribute("id") == 814);  foreach (xelement el in siteuserelements) {     console.writeline("el: " + el); } 

Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -