Skip to content

XML Rules in 7.0.0 #4880

Answered by adangel
justinstroudbah asked this question in Q&A
Mar 23, 2024 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

Hi @justinstroudbah ,

there is indeed no visitor or something like that. So far, we only have written XPath based rules, we didn't have a need yet to write Java rule.

But the entry point for Java-based rules is:

  • Subclass net.sourceforge.pmd.lang.xml.rule.AbstractXmlRule
  • override the method void apply(Node target, RuleContext ctx)
  • this gives you the root node of the XML document. You can assume at this point, that it is a net.sourceforge.pmd.lang.xml.ast.XmlNode.
  • from there, you can use the NodeStream API to query the "AST".

We probably didn't write a visitor, because there are not really different node types - there is only one possible node type, and that is XmlNode... so, we would hav…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@justinstroudbah
Comment options

@adangel
Comment options

Answer selected by justinstroudbah
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants