Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## edu.stanford.nlp.util
Class XMLUtils

    java.lang.Object
      edu.stanford.nlp.util.XMLUtils

    public class XMLUtils

extends Object

Provides some utilities for dealing with XML files, both by properly parsing them and by using the methods of a desperate Perl hacker.

Author:
  Teg Grenager

Nested Class Summary
`static class` | `XMLUtils.XMLTag`

Field Summary
`static Set<String>` | `breakingTags` Block-level HTML tags that are rendered with surrounding line breaks.

Method Summary
`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 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)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### breakingTags

    public static final Set<String> breakingTags

  Block-level HTML tags that are rendered with surrounding line breaks.

Method Detail

### stripTags

    public static String stripTags(Reader r,
                                   List<Integer> mapBack,
                                   boolean markLineBreaks)

  Parameters:
    `r` - the reader to read the XML/HTML from
    `mapBack` - a List of Integers mapping the positions in the result buffer to positions in the original Reader, will be cleared on receipt
  Returns:
    the String containing the resulting text

### isBreaking

    public static boolean isBreaking(String tag)

### isBreaking

    public static boolean isBreaking(XMLUtils.XMLTag tag)

### readUntilTag

    public static String readUntilTag(Reader r)
                               throws IOException

  Reads all text up to next XML tag and returns it as a String.

  Returns:
    the String of the text read, which may be empty.
  Throws:
    `IOException`

### readAndParseTag

    public static XMLUtils.XMLTag readAndParseTag(Reader r)
                                           throws Exception

  Returns:
    the new XMLTag object, or null if couldn't be created
  Throws:
    `Exception`

### unescapeStringForXML

    public static String unescapeStringForXML(String s)

### escapeXML

    public static String escapeXML(String in)

  Returns a String in which all the XML special characters have been escaped. The resulting String is valid to print in an XML file as an attribute or element value in all circumstances. (Note that it may escape characters that didn't need to be escaped.)

  Parameters:
    `in` - The String to escape
  Returns:
    The escaped String

### escapeElementXML

    public 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.

  Parameters:
    `in` - The String to escape
  Returns:
    The escaped String

### escapeAttributeXML

    public static String escapeAttributeXML(String in)

  Returns a String in which some XML special characters have been escaped. This just escapes attribute value ones, assuming that you're going to quote with double quotes. That is, only " and & are escaped.

  Parameters:
    `in` - The String to escape
  Returns:
    The escaped String

### escapeTextAroundXMLTags

    public static String escapeTextAroundXMLTags(String s)

### readTag

    public static String readTag(Reader r)
                          throws IOException

  Reads all text of the XML tag and returns it as a String. Assumes that a '<' character has already been read.

  Parameters:
    `r` - The reader to read from
  Returns:
    The String representing the tag, or null if one couldn't be read (i.e., EOF). The returned item is a complete tag including angle brackets, such as `<TXT>`
  Throws:
    `IOException`

### parseTag

    public static XMLUtils.XMLTag parseTag(String tagString)
                                    throws Exception

  Throws:
    `Exception`

### readDocumentFromFile

    public static Document readDocumentFromFile(String filename)
                                         throws Exception

  Throws:
    `Exception`

### readDocumentFromString

    public static Document readDocumentFromString(String s)
                                           throws Exception

  Throws:
    `Exception`

### main

    public static void main(String[] args)
                     throws Exception

  Tests a few methods. If the first arg is -readDoc then this method tests readDocumentFromFile. Otherwise, it tests readTag/readUntilTag and slurpFile.

  Throws:
    `Exception`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Stanford NLP Group