C# XML to Linq element name not working -
i trying consume rest web service using c# getting error when trying values of individual data points in xml string.
the xml looks this:
<queryresult xmlns="http://www.example.com" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"> <records xsi:type="sobject"> <type>account</type> <id>0013000000lkoumaa5</id> <name>example inc.</name> <billingcountry>us</billingcountry> <website>http://www.example.com</website> <createdbyid>00530000000i1jaaaq</createdbyid> <createddate>2008-02-04t14:51:23.000z</createddate> <lastmodifieddate>2014-04-02t18:10:32.000z</lastmodifieddate> <lastmodifiedbyid>00580000005ptwaaau</lastmodifiedbyid> </records> </queryresult>
using following code able parse xml string not return value "name" element, returning following error: "object reference not set instance of object."
webresponse response = request.getresponse(); xmlreader reader = xmlreader.create(response.getresponsestream()); xdoc = xdocument.load(reader); xnamespace ns = "http://www.example.com"; ienumerable<xelement> records = el in xdoc.descendants(ns + "records") select el; foreach (xelement record in records) { console.writeline("website: " + record.element(ns + "website").value); //this line works console.writeline("name: " + record.element(ns + "name").value); //returns error }
i figuring has element name being "name". have been working on day , stuck @ point.
Comments
Post a Comment