Skip to main content
These helpers read XML elements, attributes, and indentation from nodes produced by codemod:ast-grep/langs/xml.

elementByTagRule

Return an ast-grep rule that matches an XML element whose start tag or empty-element tag equals tag. Example

findElementsByTag

Return every XML element under root whose start tag or empty-element tag matches tag.

findElementByTag

Return the first XML element under node whose start tag or empty-element tag matches tag, or null when none matches.

findElementByKind

Return the first descendant of node whose tree-sitter kind is kind, or null when none matches. kind is an XML node kind such as "ETag" or "Attribute".

getAttributeValue

Return the unquoted value of attrName on this element’s own start tag or empty-element tag. Attributes on descendant elements are ignored. Returns null when the attribute is missing. Example

hasTag

Return whether root contains an element whose start tag or empty-element tag matches tag.

getLineIndent

Return the spaces or tabs between the start of the line and node. Pass the file source as src. Returns an empty string when non-whitespace text appears before node on that line. Example