c# - How to access element in XML files with attribute values? -


this xml file

<colleges>      <college college_name="dypsoe">         <departments>             <department department_name="computer" id="10">             <![cdata[i need change comment!]]>             </department>             <department department_name="machanical" id="20">             <![cdata[i need change comment!]]>             </department>         </departments>     </college>      <college college_name="dypsoet">         <departments>             <department department_name="computer" id="10">             <![cdata[i need change comment!]]>             </department>             <department department_name="machanical" id="20">             <![cdata[i need change comment!]]>             </department>         </departments>     </college>  </colleges> 

i have 3 attribute values college_name, department_name , id available in program. want go particular "department" node , change value in comments these 3 attribute values.

i'am trying reach node different queries, failed far.

var node = e in doc.descendants("college")            e.attribute("college_name").tostring() == college_name            select (xelement)e.elements("department");   foreach (xelement data in node) {     console.writeline(data); //just got     data.value = ""; //to change comment section } 

this not working @ all. if guys suggest me query me lot.

presuming want select single department element based on college , department names, can find using query one:

var query = college in doc.descendants("college")             (string) college.attribute("college_name") == "dypsoe"             department in college.descendants("department")             (string) department.attribute("department_name") == "computer"             select department;  var element = query.single(); 

you can replace comment this:

element.replacenodes(new xcdata("new comment")); 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -