Question

I need to express in xml a list of actions that my program can do. The problem is that some actions need of additional elements and others do not. For example if my program has to perform actions on files: if I delete the only thing that interests me is the path, if the program does the copy... again I need the path, but also a path of destination .. How to write an xml file so structured?

Was it helpful?

Solution

Something like this?

<actions>
  <action name="FileCopy">
    <params>
      <param name="SourcePath" value="c:\source.txt"/>
      <param name="DestPath" value="c:\dest.txt"/>
    </params>
  </action>
  <action name="FileDelete">
    <params>
      <param name="DeletePath" value="c:\source.txt"/>
    </params>
  </action>
  <action name="ReloadCache"/>
  <action name="Alert">
   <params>
     <param name="Message" value="Done!"/>
   </params>
  </action>
</actions>

You could of course remove the params level and put param tags directly under the action tag, however the proposed structure will allow to add other types of nodes under the action tag (for example, validation callbacks) without breaking too much things.

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