de.cbse.jeasy
Class JESimpleParser

java.lang.Object
  extended by de.cbse.jeasy.JESimpleParser

public class JESimpleParser
extends java.lang.Object

Some simple methods to parse a string in XML format.
The methods use no SAXParser but some native string functions instead.
Its faster than to use a SAXParser.

See a demonstration in the program JEasyExample tab "Adress Form".

Author:
Harry Pfohl

Constructor Summary
JESimpleParser()
           
 
Method Summary
static java.lang.String getElementData(java.lang.String source, java.lang.String element)
          Returns the String between and with substitution of special XML characters.
static java.lang.String getXMLAttribute(java.lang.String source, java.lang.String attribut)
          Parses the String for the attribut (attribut="value")
static java.lang.String getXMLElementAttribute(java.lang.String source, java.lang.String element, java.lang.String attribut)
          Parses the String for the attribut inside the the given XML-Element inside
static java.lang.String getXMLElementByAttributeValue(java.lang.String source, java.lang.String element, java.lang.String attribute, java.lang.String value)
          Parses the String for the given XML-Elements.
static java.lang.String getXMLSubString(java.lang.String source, java.lang.String element)
          Returns the String between and without substitution of special XML characters.
static java.lang.String getXMLSubStringEmpty(java.lang.String source, java.lang.String element)
          Returns the String between and without substitution of special XML characters.
static java.util.Vector getXMLSubStringVector(java.lang.String source, java.lang.String element)
          Parses the String for the given XML-Elements and returns a vector with all text between te starttag and the endtag
static java.util.Vector getXMLVector(java.lang.String source)
          Parses the String for all tags and returns them as a vector
static java.lang.String replaceXMLElement(java.lang.String source, java.lang.String element, java.lang.String value)
          Replaces the String between the first occurrence of and
static java.lang.String str2Xml(java.lang.String str)
          Replaces < > & and ' into XML entities
static java.lang.String xml2str(java.lang.String str)
          Replaces general XML entities inside a ISO-8859-1 encoding String into char
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JESimpleParser

public JESimpleParser()
Method Detail

getXMLSubString

public static java.lang.String getXMLSubString(java.lang.String source,
                                               java.lang.String element)
Returns the String between and without substitution of special XML characters. Use it only to read xml substructures. To read XMl elements please use getElemetData(...)

Parameters:
source - the string where it will be searched
element - the XML element to look for
Returns:
the string inside the tag or null

getElementData

public static java.lang.String getElementData(java.lang.String source,
                                              java.lang.String element)
Returns the String between and with substitution of special XML characters.

Parameters:
source - the string where it will be searched
element - the XML element to look for
Returns:
the string inside the tag or null

getXMLSubStringEmpty

public static java.lang.String getXMLSubStringEmpty(java.lang.String source,
                                                    java.lang.String element)
Returns the String between and without substitution of special XML characters.

Parameters:
source - the string where it will be searched
element - the XML element to look for
Returns:
the string inside the tag or an empty String

getXMLElementAttribute

public static java.lang.String getXMLElementAttribute(java.lang.String source,
                                                      java.lang.String element,
                                                      java.lang.String attribut)
Parses the String for the attribut inside the the given XML-Element inside

Parameters:
source - the string where it will be searched
element - the XML element to look for
Returns:
the string inside the tag or null

getXMLElementByAttributeValue

public static java.lang.String getXMLElementByAttributeValue(java.lang.String source,
                                                             java.lang.String element,
                                                             java.lang.String attribute,
                                                             java.lang.String value)
Parses the String for the given XML-Elements. If the element has the attribute and the value the element will be returned

Parameters:
source - the string where it will be searched
element - the XML element to look for
attribute - the attibute the element must have
value - and its value
Returns:
the XML string matching element , attribute and value

getXMLAttribute

public static java.lang.String getXMLAttribute(java.lang.String source,
                                               java.lang.String attribut)
Parses the String for the attribut (attribut="value")

Parameters:
source - the string where it will be searched
Returns:
the attribute vale

getXMLSubStringVector

public static java.util.Vector getXMLSubStringVector(java.lang.String source,
                                                     java.lang.String element)
Parses the String for the given XML-Elements and returns a vector with all text between te starttag and the endtag

Parameters:
source - the string where it will be searched
element - the XML element to look for
Returns:
the Vector of found strings between the tag element

getXMLVector

public static java.util.Vector getXMLVector(java.lang.String source)
Parses the String for all tags and returns them as a vector

Parameters:
source - the string where it will be searched
Returns:
the vector

replaceXMLElement

public static java.lang.String replaceXMLElement(java.lang.String source,
                                                 java.lang.String element,
                                                 java.lang.String value)
Replaces the String between the first occurrence of and

Parameters:
source - the string where it will be searched
element - the XML element to look for
value - the string to insert
Returns:
the source string with replaced value

xml2str

public static java.lang.String xml2str(java.lang.String str)
Replaces general XML entities inside a ISO-8859-1 encoding String into char

Parameters:
s - xml-String
Returns:
the new String

str2Xml

public static java.lang.String str2Xml(java.lang.String str)
Replaces < > & and ' into XML entities

Parameters:
s - String
Returns:
the new String