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

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -