JCas
v0.3.1

cas.xml
Class XmlUtils

java.lang.Object
  extended bycas.xml.XmlUtils

public class XmlUtils
extends Object

Helper class for parsing XML files.

Version:
1.0
Author:
Ralph Schuster

Constructor Summary
XmlUtils()
           
 
Method Summary
static Node getChild(Node root, String name)
          Returns the first node with the specified tag name.
static Node getChild(Node root, String name, int n)
          Returns the n-th node with the specified tag name.
static Node getChild(Node root, String name, String subname, String subvalue)
          Returns the first node with the specified tag name that contains a subnode of the specified subname with a specific value n ranges from 1...
static int getChildCount(Node root, String name)
          Returns the number of nodes with the specified name.
static String getNodeContent(Node root, String name)
          Returns the text that is contained in a tag <name> under the root node.
static Element parseDOM(File xmlFile)
          Parses the file and returns the root element for parsing.
static Element parseDOM(String xmlFile)
          Parses the file and returns the root element for parsing.
static void parseSax(File file, DefaultHandler handler)
          Parses an XML file with default SAX parser.
static void parseSax(InputStream in, DefaultHandler handler)
          Parses an InputStream with default SAX parser.
static void parseSax(InputStream in, DefaultHandler handler, boolean logLocation)
          Parses an InputStream with default SAX parser.
static void parseSax(String file, DefaultHandler handler)
          Parses an XML file with default SAX parser.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlUtils

public XmlUtils()
Method Detail

parseDOM

public static Element parseDOM(File xmlFile)
Parses the file and returns the root element for parsing.


parseSax

public static void parseSax(InputStream in,
                            DefaultHandler handler)
                     throws IOException,
                            SAXException,
                            ParserConfigurationException
Parses an InputStream with default SAX parser.

Parameters:
in - the stream to parse
handler - the SAX Content handler.
Throws:
IOException
SAXException
ParserConfigurationException

parseSax

public static void parseSax(InputStream in,
                            DefaultHandler handler,
                            boolean logLocation)
                     throws IOException,
                            SAXException,
                            ParserConfigurationException
Parses an InputStream with default SAX parser.

Parameters:
in - the stream to parse
handler - the SAX Content handler.
logLocation - true if the location should be logged in case of an error.
Throws:
IOException
SAXException
ParserConfigurationException

parseSax

public static void parseSax(File file,
                            DefaultHandler handler)
                     throws IOException,
                            SAXException,
                            ParserConfigurationException
Parses an XML file with default SAX parser.

Parameters:
file - the XML file to parse
handler - the SAX Content handler.
Throws:
IOException
SAXException
ParserConfigurationException

getNodeContent

public static String getNodeContent(Node root,
                                    String name)
Returns the text that is contained in a tag <name> under the root node.


getChildCount

public static int getChildCount(Node root,
                                String name)
Returns the number of nodes with the specified name.


getChild

public static Node getChild(Node root,
                            String name)
Returns the first node with the specified tag name.


getChild

public static Node getChild(Node root,
                            String name,
                            String subname,
                            String subvalue)
Returns the first node with the specified tag name that contains a subnode of the specified subname with a specific value n ranges from 1...


getChild

public static Node getChild(Node root,
                            String name,
                            int n)
Returns the n-th node with the specified tag name. n ranges from 1...


parseDOM

public static Element parseDOM(String xmlFile)
Parses the file and returns the root element for parsing.


parseSax

public static void parseSax(String file,
                            DefaultHandler handler)
                     throws IOException,
                            SAXException,
                            ParserConfigurationException
Parses an XML file with default SAX parser.

Parameters:
file - the XML file to parse
handler - the SAX Content handler.
Throws:
IOException
SAXException
ParserConfigurationException

JCas
v0.3.1