Write xml file with elements depending on the type of action to be performed

StackOverflow https://stackoverflow.com/questions/4715289

  •  12-10-2019
  •  | 
  •  

سؤال

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?

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top