com.itextpdf.text.xml
Class XmlToTxt

java.lang.Object
  extended by com.itextpdf.text.xml.XmlToTxt
All Implemented Interfaces:
SimpleXMLDocHandler

public class XmlToTxt
extends Object
implements SimpleXMLDocHandler

This class converts XML into plain text stripping all tags.


Field Summary
protected  StringBuffer buf
          Buffer that stores all content that is encountered.
 
Constructor Summary
protected XmlToTxt()
          Creates an instance of XML to TXT.
 
Method Summary
 void endDocument()
          Called after the document is parsed.
 void endElement(String tag)
          Called when an end tag is found.
static String parse(InputStream is)
          Static method that parses an XML InputStream.
 void startDocument()
          Called when the document starts to be parsed.
 void startElement(String tag, Map<String,String> h)
          Called when a start tag is found.
 void text(String str)
          Called when a text element is found.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

buf

protected StringBuffer buf
Buffer that stores all content that is encountered.

Constructor Detail

XmlToTxt

protected XmlToTxt()
Creates an instance of XML to TXT.

Method Detail

parse

public static String parse(InputStream is)
                    throws IOException
Static method that parses an XML InputStream.

Parameters:
is - the XML input that needs to be parsed
Returns:
a String obtained by removing all tags from the XML
Throws:
IOException

toString

public String toString()
Overrides:
toString in class Object
Returns:
the String after parsing.

startElement

public void startElement(String tag,
                         Map<String,String> h)
Description copied from interface: SimpleXMLDocHandler
Called when a start tag is found.

Specified by:
startElement in interface SimpleXMLDocHandler
Parameters:
tag - the tag name
h - the tag's attributes
See Also:
SimpleXMLDocHandler.startElement(java.lang.String, java.util.Map)

endElement

public void endElement(String tag)
Description copied from interface: SimpleXMLDocHandler
Called when an end tag is found.

Specified by:
endElement in interface SimpleXMLDocHandler
Parameters:
tag - the tag name
See Also:
SimpleXMLDocHandler.endElement(java.lang.String)

startDocument

public void startDocument()
Description copied from interface: SimpleXMLDocHandler
Called when the document starts to be parsed.

Specified by:
startDocument in interface SimpleXMLDocHandler
See Also:
SimpleXMLDocHandler.startDocument()

endDocument

public void endDocument()
Description copied from interface: SimpleXMLDocHandler
Called after the document is parsed.

Specified by:
endDocument in interface SimpleXMLDocHandler
See Also:
SimpleXMLDocHandler.endDocument()

text

public void text(String str)
Description copied from interface: SimpleXMLDocHandler
Called when a text element is found.

Specified by:
text in interface SimpleXMLDocHandler
Parameters:
str - the text element, probably a fragment.
See Also:
SimpleXMLDocHandler.text(java.lang.String)


Copyright © 2014. All Rights Reserved.