If you use the HTTP API, you can use the data parameter as documented at LanguageTool HTTP API. From Java, you’d need to define the text and markup ranges using AnnotatedTextBuilder.
An alternative is to add a rule in disambiguation.xml that ignores text that is inside a tag. Use this as a template:
<rule id="IGNORE_SPELLING_IN_XML_TAGS" name="Ignore spelling in XML tags">
<pattern>
<token regexp="yes"><</token>
<token regexp="yes">skip|mytag</token>
<token regexp="yes">></token>
<marker>
<token regexp="yes">\p{L}+</token><!-- One or more letters in any language -->
</marker>
<token regexp="yes"><</token>
<token>/</token>
<token><match no="1"/></token>
<token regexp="yes">></token>
</pattern>
<disambig action="ignore_spelling"/>
</rule>
To ignore the tags such that the grammar checking does not give an error for correct text (ignoring the tags), you can immunize the tags. (I have not done tests to confirm.) Refer to Developing a Disambiguator - LanguageTool Wiki.