Question

EDIT: here can be found a similar question w/ answer

Ok, so I need to be able to edit a profile in a GUI (all fields except Profile Name) or select a Profile (by Name) to be removed from the xml document I'm using.

Currently I have a listView that holds all Items in the XML doc as 'profile' objects (consisting of 3 strings and dividing Collections element into 3 bool values) I have an idea on how to delete items, I could simply remove one from the listview and then write the remaining items to the xml, BUT how do I do that so it isn't adding to the file, but rather overwriting its content?

Also Is there a way to edit an element via searching for its Profile by name and tweaking its child nodes? let me know if there's a more efficient deletion method and the best way to edit node's children!

to summarize:

  1. how should I go about deleting profiles?
  2. how is the best way to edit a nodes child elements?

Example XML file to be worked with:

<?xml version="1.0" encoding="utf-8"?>
<Profiles>
  <Profile Name="Tool3927">
    <ToolName>01.11.1221</ToolName>
    <SaveLocation>C:\Users\13\Desktop</SaveLocation>
    <Collections>False.True.False</Collections>
  </Profile>
  <Profile Name="MyTool">
    <ToolName>US.01.8280</ToolName>
    <SaveLocation>C:\Users\13\Desktop</SaveLocation>
    <Collections>True.True.True</Collections>
  </Profile>
  <Profile Name="TestProfile">
    <ToolName>11.11.1111</ToolName>
    <SaveLocation>C:\</SaveLocation>
    <Collections>True.False.False</Collections>
  </Profile>
  <Profile Name="a">
    <ToolName>za-za-zaza</ToolName>
    <SaveLocation>C:\Users\13\Desktop\tester</SaveLocation>
    <Collections>False.True.False</Collections>
  </Profile>
</Profiles>
Was it helpful?

Solution

I would use XPath to get at the nodes you want to delete and then see this answer for the code to do the deletion.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top