So, here is my case.
I have an XElement, let it root, which has descendants, which have descendants, etc. I pull the descendant using LINQ to XML, load it into the note editor using .ToString() and editing it. Now I want to update / replace the original child element with the edited version.
Let me mention that this is a simple XML file, without a schema, not using the DOM, etc. I only need to edit and update / replace the item.
Here is the layout of my XML:
<Root> <Genre Name="Rock"> <Artist Name="Pink Floyd"> <BandMembers> <Member>Nick Mason</Member> <Member>Syd Barret</Member> <Member>David Gilmour</Member> <Member>Roger Water</Member> <Member>Richard Wright</Member> </BandMembers> <Category>Favorite band of all time</Category> </Artist> <Artist Name="Led Zepelin"> <Category>Love the band</Category> </Artist> </Genre> <Genre Name="Blues"> <Artist Name="Muddy Waters"> <Instrument>Harmonica</Instrument> </Artist> <Artist Name="Howling Wolf"> <Instrument>Guitar</Instrument> </Artist> </Genre> </Root>
Now say that I want to edit the Pink Floyd element to fix the name of Roger Waters. I get this element, convert it to a string, load it into my editor, make the necessary changes and convert it back to XElement using .Parse() .
Now, how can I update / replace the "Pink Floyd" node in my source XML?
source share