c# - ASP.NET LINQ to XML how to reach an node/element just giving the name? -
of following code want bold elements: _connectionid , return.
there 2 return tags, need "return" , relative value , same "_connectionid"
<envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xs="http://www.w3.org/2001/xmlschema" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" <body> <login_newresponse xmlns=\"http:xxxxxxxxxxxx.wsdl"> <return> <_**connectionid**>@@@@@@@@@@@@@aht@q@@@@@d@gr@suef</_**connectionid**> <**return**>connessione avvenuta</**return**> </return> </login_newresponse> </body> </envelope>
i've tried code
xdocument xml = xdocument.load(s); var lv1s = lv1 in xml.descendants("body") select lv1.nodes();
i list of xml strings it's impossible specific element. there way extract whatever element indicating name?
thanks!
if want find 2 values, can do:
xnamespace ns = "http:xxxxxxxxxxxx.wsdl"; var data = xml.root.elements("body").elements(ns + "login_newresponse").elements(ns + "return") .select(e => new { connectionid = (string)e.element(ns + "_connectionid"), return = (string)e.element(ns + "return") }) .firstordefault();
likely you'll need replace "http:xxxxxxxxxxxx.wsdl"
"real" namespace.
Comments
Post a Comment