문제

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