有没有办法检查给定元素X是否传递给macrodef。我有一个案例来决定元素X是必需的还是可选的。为了达到这个目的,我为所有情况选择了元素, 但我想在缺少元素的情况下进行验证,如果允许丢失元素: - )。
宏看起来像这样:
File->Settings->Code Style->JSON
元素X看起来就像元素Y.我的意思是,如果它存在,它将包含另一个嵌套元素。
我理解这个概念的方式可能是错的。我会尝试举另一个例子。 目前元素X是强制性的,我的任务是在某些情况下使其成为可选项,但在其他情况下则是强制性的。我希望能够以两种方式使用宏,但我不知道如何实现这个任务:
<macrodef name="test">
<attribute name="attribute1"/>
......
<attribute name="attributeN/>
<element name="X" optional="true/>
<element name="Y" optional="true/>
<sequential>
<local>
<!--here check if the element <X/> is passed -->
</local>
</sequential>
</macrodef>
<test attribute1="1", attributeN="N">
<!--Here do not provide element X. Only provide Y-->
<Y>
<nestedY1>Some text1</nestedY1>
<nestedY2>Some text2</nestedY2>
</Y>
</test>