public class XmlHighlighter extends Object
Modifier and Type | Class and Description |
---|---|
static class |
XmlHighlighter.HitCharSpan
The start and end character position of a hit, used for highlighting the
content.
|
static class |
XmlHighlighter.UnbalancedTagsStrategy
How to deal with non-well-formed snippets: by e.g.
|
Constructor and Description |
---|
XmlHighlighter() |
Modifier and Type | Method and Description |
---|---|
String |
cutAroundTags(String elementContent,
int stopAfterChars)
Cut a string after a specified number of non-tag characters, preferably at a
word boundary, keeping all tags after the cut intact.
|
XmlHighlighter.UnbalancedTagsStrategy |
getUnbalancedTagsStrategy()
Get how well-formedness problems are fixed
|
String |
highlight(String elementContent,
List<XmlHighlighter.HitCharSpan> hits)
Highlight a string containing XML tags.
|
String |
highlight(String partialContent,
List<XmlHighlighter.HitCharSpan> hits,
int offset)
Highlight part of an XML document.
|
static void |
main(String[] args) |
String |
makeWellFormed(String xmlFragment)
Make a cut XML fragment well-formed.
|
void |
setRemoveEmptyHlTags(boolean c)
Set whether or not to remove empty
|
void |
setUnbalancedTagsStrategy(XmlHighlighter.UnbalancedTagsStrategy strategy)
Set how to fix well-formedness problems.
|
public String highlight(String elementContent, List<XmlHighlighter.HitCharSpan> hits)
elementContent
- the string to highlighthits
- where the highlighting tags should gopublic String highlight(String partialContent, List<XmlHighlighter.HitCharSpan> hits, int offset)
partialContent
- the (partial) XML to cut and highlight.hits
- the hits to use for highlighting, or null for no highlightingoffset
- position of the first character in the string (i.e. what to
subtract from Hit positions to highlight)public String cutAroundTags(String elementContent, int stopAfterChars)
elementContent
- the string to cutstopAfterChars
- after how many non-tag characters we should stop (-1
for no limit)public static void main(String[] args)
public void setRemoveEmptyHlTags(boolean c)
c
- true iff empty hl tags should be removedpublic String makeWellFormed(String xmlFragment)
xmlFragment
- public XmlHighlighter.UnbalancedTagsStrategy getUnbalancedTagsStrategy()
public void setUnbalancedTagsStrategy(XmlHighlighter.UnbalancedTagsStrategy strategy)
strategy
- what to do when encountering unbalanced tags.Copyright © 2020 Instituut voor Nederlandse Taal (INT). All rights reserved.