public class XMLUtils extends Object
Modifier and Type | Class and Description |
---|---|
static class |
XMLUtils.XMLTag |
Modifier and Type | Method and Description |
---|---|
static String |
escapeAttributeXML(String in)
Returns a String in which some XML special characters have been
escaped.
|
static String |
escapeElementXML(String in)
Returns a String in which some the XML special characters have been
escaped: just the ones that need escaping in an element content.
|
static String |
escapeTextAroundXMLTags(String s) |
static String |
escapeXML(String in)
Returns a String in which all the XML special characters have been
escaped.
|
static int |
findSpace(String haystack,
int begin)
return either the first space or the first nbsp
|
static List<Element> |
getTagElementsFromFile(File f,
String tag)
Returns the text content of all nodes in the given file with the given tag.
|
static List<Triple<String,Element,String>> |
getTagElementTriplesFromFile(File f,
String tag)
Returns the elements in the given file with the given tag associated with
the text content of the two previous siblings and two next siblings.
|
static List<Triple<String,Element,String>> |
getTagElementTriplesFromFileNumBounded(File f,
String tag,
int num)
Returns the elements in the given file with the given tag associated with
the text content of the previous and next siblings up to max numIncludedSiblings.
|
static List<Triple<String,Element,String>> |
getTagElementTriplesFromFileNumBoundedSAXException(File f,
String tag,
int numIncludedSiblings)
Returns the elements in the given file with the given tag associated with
the text content of the previous and next siblings up to max numIncludedSiblings.
|
static List<Triple<String,Element,String>> |
getTagElementTriplesFromFileSAXException(File f,
String tag)
Returns the elements in the given file with the given tag associated with
the text content of the two previous siblings and two next siblings.
|
static List<String> |
getTextContentFromTagsFromFile(File f,
String tag)
Returns the text content of all nodes in the given file with the given tag.
|
static DocumentBuilder |
getValidatingXmlParser(File schemaFile)
Returns a validating XML parser given an XSD (not DTD!).
|
static DocumentBuilder |
getXmlParser()
Returns a non-validating XML parser.
|
static boolean |
isBreaking(String tag) |
static boolean |
isBreaking(XMLUtils.XMLTag tag) |
static void |
main(String[] args)
Tests a few methods.
|
static XMLUtils.XMLTag |
parseTag(String tagString) |
static XMLUtils.XMLTag |
readAndParseTag(Reader r) |
static Document |
readDocumentFromFile(String filename) |
static Document |
readDocumentFromString(String s) |
static String |
readTag(Reader r)
Reads all text of the XML tag and returns it as a String.
|
static String |
readUntilTag(Reader r)
Reads all text up to next XML tag and returns it as a String.
|
static String |
stripTags(Reader r,
List<Integer> mapBack,
boolean markLineBreaks) |
static String |
unescapeStringForXML(String s) |
public static List<String> getTextContentFromTagsFromFile(File f, String tag)
public static List<Element> getTagElementsFromFile(File f, String tag)
public static List<Triple<String,Element,String>> getTagElementTriplesFromFile(File f, String tag)
Triple<String, Element, String>
Targeted elements surrounded
by the text content of the two previous siblings and two next siblings.public static List<Triple<String,Element,String>> getTagElementTriplesFromFileNumBounded(File f, String tag, int num)
Triple<String, Element, String>
Targeted elements surrounded
by the text content of the two previous siblings and two next siblings.public static List<Triple<String,Element,String>> getTagElementTriplesFromFileSAXException(File f, String tag) throws SAXException
Triple<String, Element, String>
Targeted elements surrounded
by the text content of the two previous siblings and two next siblings.SAXException
- if tag doesn't exist in the file.public static List<Triple<String,Element,String>> getTagElementTriplesFromFileNumBoundedSAXException(File f, String tag, int numIncludedSiblings) throws SAXException
Triple<String, Element, String>
Targeted elements surrounded
by the text content of the two previous siblings and two next siblings.SAXException
- if tag doesn't exist in the file.public static DocumentBuilder getXmlParser()
public static DocumentBuilder getValidatingXmlParser(File schemaFile)
schemaFile
- File wit hXML schemapublic static String stripTags(Reader r, List<Integer> mapBack, boolean markLineBreaks)
r
- the reader to read the XML/HTML frommapBack
- a List of Integers mapping the positions in the result buffer
to positions in the original Reader, will be cleared on receiptpublic static boolean isBreaking(String tag)
public static boolean isBreaking(XMLUtils.XMLTag tag)
public static String readUntilTag(Reader r) throws IOException
IOException
public static XMLUtils.XMLTag readAndParseTag(Reader r) throws IOException
IOException
public static String escapeXML(String in)
in
- The String to escapepublic static String escapeElementXML(String in)
in
- The String to escapepublic static String escapeAttributeXML(String in)
in
- The String to escapepublic static int findSpace(String haystack, int begin)
public static String readTag(Reader r) throws IOException
r
- The reader to read from<TXT>
IOException
public static XMLUtils.XMLTag parseTag(String tagString)
public static Document readDocumentFromFile(String filename) throws Exception
Exception
public static Document readDocumentFromString(String s) throws Exception
Exception