Skip to content

hardis:project:clean:xml

Description

Remove XML elements using Glob patterns and XPath expressions

This can be very useful to avoid to always remove manually the same elements in the same XML file.

  • globpattern can be any glob pattern allowing to identify the XML files to update, for example /**/*.flexipage-meta.xml
  • xpath can be any xpath following the format //ns:PARENT-TAG-NAME//ns:TAG-NAME[contains(text(),'TAG-VALUE')]. If an element is found, the whole PARENT-TAG-NAME (with its subtree) will be removed.

How to build cleaning XPath

Note: If globpattern and xpath are not sent, elements defined in property cleanXmlPatterns in .sfdx-hardis.yml config file will be used

Agent Mode

Supports non-interactive execution with --agent:

sf hardis:project:clean:xml --agent --globpattern "/**/*.flexipage-meta.xml" --xpath "//ns:flexiPageRegions//ns:name[contains(text(),'dashboardName')]"

In agent mode:

  • The interactive prompt to add the cleaning rule to permanent configuration is skipped.
  • Cleaning is performed using the provided flags or the existing cleanXmlPatterns configuration.

Screenshots

The activity panel removed from the Lightning pages of the Helios project, with an XPath given on the command line

The activity panel removed from the Lightning pages of the Helios project, with an XPath given on the command line

Parameters

Name Type Description Default Required Options
agent boolean Run in non-interactive mode for agents and automation
debug
-d
boolean Activate debug mode (more logs)
flags-dir option Import flag values from a directory.
folder
-f
option Root folder force-app
globpattern
-p
option Glob pattern to find files to clean. Ex: /**/*.flexipage-meta.xml
json boolean Format output as json.
namespace
-n
option XML Namespace to use http://soap.sforce.com/2006/04/metadata
skipauth boolean Skip authentication check when a default username is required
websocket option Websocket host:port for VsCode SFDX Hardis UI integration
xpath
-x
option XPath to use to detect the elements to remove. Ex: //ns:flexiPageRegions//ns:name[contains(text(),'dashboardName')]

Examples

$ sf hardis:project:clean:xml
$ sf hardis:project:clean:xml --globpattern "/**/*.flexipage-meta.xml" --xpath "//ns:flexiPageRegions//ns:name[contains(text(),'dashboardName')]"
$ sf hardis:project:clean:xml --agent

Comments