Detect Element (detectElement)

<detectElement> Element

The detectElement rule is used to find elements in XML files.

Table 1. <detectElement> Element Attributes
Attribute Name Type Required Description
tags String No

Element name. If providing multiple, use a comma separated list. If not specified, will match any element that meets the other criteria for the rule.

value Regex No

The value of the element's text content.

namespace Regex No

Only flag results if the URI of the namespace the element belongs to matches this pattern. If the pattern is "*", flag elements in any namespace, including elements with no namespace specified. Defaults to "*".

documentNamespace Regex No

Only flag results if the document namespace for the file matches this namespace pattern. Results will not be flagged in any file that does not have a document namespace specified. If both documentNamespace and validateDocumentNamespaceIfPresent are specified, documentNamespace is used.

validateDocumentNamespaceIfPresent Regex No

Flag results if the document namespace for the file does not match this namespace pattern, and in any file that does not have a document namespace specified. Use this attribute to flag XML files that don't conform to a specific document namespace. If both documentNamespace and validateDocumentNamespaceIfPresent are specified, documentNamespace is used.

missingChildElement String No

Flag the element specified by the tags attribute if it does not contain a child element of this name.

missingChildElementValue Regex No

Flag the element specified by the tags attribute if it does not contain the missingChildElement with a value that matches this.

missingChildElementAttribute String No

Flag the element specified by the tags attribute if it does not contain the missingChildElement with an attribute of this name.

missingChildElementAttributeValue Regex No

Flag the element specified by the tags attribute if it does not contain the missingChildElement with the missingChildElementAttribute with a value that matches this.

parentTags String No

Flag the element specified if it is a child element of this tag. If specifying multiple, use a comma separated list. Ignored if flagRootNode is set to "true".

flagNotEmpty Boolean No

Indicates whether the element specified by the tags attribute should be flagged only when it is not empty (contains children). Specifying "false" flags elements regardless of count of children. Defaults to false.

flagDuplicate Boolean No

Indicates that the rule should only flag if two or more instances of the element are found in the same XML file. Defaults to false.

flagRootNode Boolean No

Indicates that the rule should only flag if the element is the root node of the XML file. Defaults to false.

flagNoRootNode Boolean No

If set to true, indicates that the rule should only flag if the XML file contains no root node. Does not flag files where a root node starts but is never terminated, or files with multiple root nodes. Defaults to false.

flagOnce Boolean No

Indicates whether to flag once per archive. Defaults to false.

flagOncePerFile Boolean No

Indicates whether to flag once per file. Defaults to false.

hideResult Boolean No

Indicates whether results flagged by this rule should be hidden in the report. This attribute only hides results when used with rules under the <and> or <or> tags. Defaults to false.

Child Elements (One or more)

<xmlFile> Element - required, can be multiple

Table 2. <xmlFile> Element Attributes
Attribute Name Type Required Description
pattern Regex Yes

File name with or without path.

For example, to detect a security-constraint or auth-method element in a web.xml file located in an application's WEB-INF directory, specify:


<detectElement tags="security-constraint, auth-method">
    <xmlFile pattern="WEB-INF/web.xml"/>
</detectElement>