none
modify the value of an XML element RRS feed

  • Question

  • Hello,

    i code in c# and i I have an XML file (Xdocument) myFile:

    <Output>
       <Output>
         <ID> 1 </ ID>
         <Name> jack </ name>
         <Job> "director" </ Job>
       </ Output>
      <Output>
         <ID> 2 </ ID>
         <Name> george </ name>
         <Job> "doctor" </ Job>
       </ Output>
       <Output>
         <ID> 3 </ ID>
         <Name> philipe </ name>
         <Job> "prof" </ Job>
       </ Output>
       <Output>
             .........
    </ Output>

    I want to delete the quotes("")of the element Job I have searched for code but the code I found is to replace a value of one attrebut with another? that i went my xml file will be 

    <Output>
       <Output>
         <ID> 1 </ ID>
         <Name> jack </ name>
         <Job> director</ Job>
       </ Output>
      <Output>
         <ID> 2 </ ID>
         <Name> george </ name>
         <Job> doctor </ Job>
       </ Output>
       <Output>
         <ID> 3 </ ID>
         <Name> philipe </ name>
         <Job> prof</ Job>
       </ Output>
       <Output>
             .........
    </ Output>

    my code :

    var xmlFile=new XDocument.load(path);
    var output = xmlFile 
    .Element("Output")
    .Elements("Output")
    .where(e=>e.Element("Id").value =="1")
    .Single();
    Output.Element("Job").Value="director";
    xmlfile.Save(path); 

    // and I have to repeat this code for all the nodes


    • Edited by raouia Monday, August 27, 2018 3:24 PM
    Monday, August 27, 2018 3:07 PM

All replies