c# - Get Atttribute value from XDocument -



c# - Get Atttribute value from XDocument -

i trying responsecode attribute value out of xml.

the xml xdocument

<idmresponse xmlns:xsd="http://www.w3.org/2001/xmlschema" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" majorversion="1" xmlns="http://www.fake.org/namespace/"> <artsheader> <response responsecode="rejected"> <requestid>1</requestid> <businesserror severity="error"> <code>idminvalidusernamepasswordloginprovided</code> <description>invalid username or password, if problem persists, please contact administrator</description> </businesserror> </response> </artsheader> </idmresponse>

with xpath: (no error checks done)

xmlnamespacemanager nsm = new xmlnamespacemanager(new nametable()); nsm.addnamespace("def", "http://www.fake.org/namespace/"); xdocument doc = xdocument.parse(xml); string code = doc .xpathselectelement(@"/def:idmresponse/def:artsheader/def:response", nsm) .attribute("responsecode") .value;

c# xml linq-to-xml

Comments

Popular posts from this blog

php - How to pass multiple values from url -

database - php search bar when I press submit with nothing in the search bar it shows all the data -

ios - How to load .png images from Documents folder of an app -