c# - How to get value of element with XDocument and Linq to XML -
i want collect requestid element namespace, not know how.
this.xmlstring = "<?xml version=\"1.0\" encoding=\"utf-8\"?><methodnamerq xmlns:xs=\"http://www.w3.org/2001/xmlschema\" xmlns:xsi=\"http://www.w3.org/2001/xmlschema-instance\"><requestid xmlns=\"http://mynamespace\">573-348976-428697-346</requestid ></methodnamerq>"; var doc = xdocument.parse(this.xmlstring); this.requestid = (string)doc.descendants().where(n => n.name == "requestid ").firstordefault(); this collects empty string requestid. work if string has no namespaces included. know how can collect requestid element?
you need specify namespace of element
xnamespace ns = "http://mynamespace"; this.requestid = (string)doc.descendants(ns + "requestid").firstordefault();
Comments
Post a Comment