Reputation: 6456
How do I set a value using XmlFile in this section?
<root>
<!--<appender-ref ref="RollingFileAppender" />-->
<level value="ALL"/>
</root>
i.e. I need to add this element and value
<appender-ref ref="RollingFileAppender" />
Is it possible to check if it exists and do not add?
Upvotes: 1
Views: 2247
Reputation: 2721
XmlFile
allows for conditionally adding elements and/or attributes by specifying the ElementPath
attribute.
The following example installs the XML file File.xml and then adds an appender-ref
element with the ref
attribute set to RollingFileAppender unless there already exists an appender-ref
element. Note that the XmlConfig
element for adding the attribute value references the other element's ID through its ElementId
attribute.
<Component>
<File Source='$(sys.SOURCEFILEDIR)File.xml'/>
<util:XmlConfig Id="CreateAppenderElement"
File="[#File.xml]"
Action="create"
ElementPath="/root"
VerifyPath="/root/appender-ref"
Name="appender-ref"
Node="element"
On="install">
<util:XmlConfig Id="CreateAppenderElement_SetRef"
ElementId="CreateAppenderElement"
File="[#File.xml]"
Name="ref"
Value="RollingFileAppender"/>
</util:XmlConfig>
</Component>
Upvotes: 7