c# - Retrieving and XDocuments attribute value via linq -


'm having problem figuring out correct select statement here

i have following xml

<configuration>   <other sections>   <runtime>     <binding xmlns="urn:schemas-microsoft-com:asm.v1">       <probing path="some path string" />     </binding>     <concurrent enabled="false" />   </runtime>   <other sections> </configuration> 

im trying select retrieve path string value

so far have this

xdocument xdoc = xdocument.load(xmlfilepath);  var query = (from c in xdoc.descendants("probing") c.attribute("path") != null select c.attribute("path").value).firstordefault(); 

but doesn't work, query null

because name of attribute path not privatepath.also can use explicit cast , don't need null-check:

var query = (from c in xdoc.descendants("probing")              select (string)c.attribute("path")).firstordefault(); 

update: seems element has namespace need specify namespace this:

xnamespace ns = "urn:schemas-microsoft-com:asm.v1";  var query = (from c in xdoc.descendants(ns + "probing")              select (string)c.attribute("path")).firstordefault(); 

you may want take @ documentation more details xml namespaces: working xml namespaces


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -