c# - LINQ-XML How should I get the error XML node with given error attribute -


here xml

get resultcode attribute, if error product's child nodes

   <product action="result" resultcode="error" resulttext="an error occurred in child   element.">            <pno>9723151113</pno>        <catalog_no resultcode="error" resulttext="invalid entry field.">1134</catalog_no>    </product> 

so first want check wheather node's attribute has error , select child node , descendent child node has error , node using linq. above,look nodes under cust check attribute 'resultcode', if has error value select node , thier child nodes find out exact error. cust -> node error ? -> product => select product => child nodes under product => select error attribute node.

i don't want put logic wil parse each , every node in loop, thinking linq use easy .any idea how achive using linq query?

try one:

var xdoc = xdocument.load(@"yourxml.xml"); var xelementwitherrors = (from xelem in doc.descendants()                           xelem.attribute("resultcode").value == "error"                           select xelem).tolist(); 

all child of product tag resultcode of "error" populated list xelementwitherrors.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -