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
Post a Comment