Grouping a series of XML nodes based on their parent nodes

时间:2016-09-01 06:09:13

标签: c# xml

I'm writing a script that will eventually clean up an XML file used by a user access provisioning system at work, based on what items are parsed in to be removed. The XML document has a various levels of child/parent nodes as below:

<Enterprise>
<Channel name="a">
 <busunit name="one">
  <dept name="x">
   <role name ="role1">
   <role name="role2">
  </dept>
  <dept name="y">
  <dept name="z">
 </busunit >
 <busunit name="two">
 <busunit name="three">     
</Channel>
<Channel name="b" >
<Channel name="c">
</Enterprise>

What I'm wanting to do is read the document and group items based on their parents, but I'm struggling to come up with a solid way of doing this because of the various node levels.

I've made a start at using a series of lists for each channel that stores a list of business units, that stores a list of departments that finally stores a list of roles (essentially a multi-dimensional list) but I'm thinking this could get terribly hard to follow quite quickly and a nightmare to debug.

A few other things to note:

  • There is no set number of busunits in a channel, nor is there a set number of depts in a busunit OR a set number of roles in depts
  • There are duplicate names of busunits/depts/roles across channels/busunits/departments (which is why this needs cleaning up)

Hopefully this isn't to vague to understand but what I'm wanting to know in a nutshell is: What other alternatives do I have at my disposal other than multi-dimensional lists to group+store multiple parent/child nodes?

Thanks in advance!

1 个答案:

答案 0 :(得分:1)

尝试将数据放入数据表中,以便于删除

RandomAccessFile