standup.xml
Class XMLUtils
java.lang.Object
standup.xml.XMLUtils
public class XMLUtils
- extends Object
A collection of utilities for handling XML files. It is based on the
XmlUtils
contained within Grok (copyright Jason Baldridge and
Gann Bierner), which in turn was based on code from The Bean Factory, LLC --
original author Nazmul Idris.
- Author:
- Ruli Manurung
Method Summary |
static boolean |
existsElement(Element e,
String tagName)
|
static String |
getAttribute(Element E,
String AttrName)
Return an Element given an XML document, tag name, and index |
static List<Element> |
getDirectElementKids(Element E)
|
static List<Element> |
getDirectElementKids(Element E,
String TagName)
|
static Element |
getElement(Element E,
String TagName)
|
static Element |
getElement(Element E,
String TagName,
int Index)
|
static List<Element> |
getNamedChildren(Element e,
List tags)
New method which returns the direct children under e which have tags
listed under the List tags. |
static int |
getSize(Element E,
List TagNames)
|
static int |
getSize(Element E,
String TagName)
|
static String |
getTextValue(Element E)
|
static String |
getTextValue(Element E,
String TagName)
|
static String |
getTextValue(Element E,
String TagName,
int Index)
|
static Document |
parseXML(File file)
Parses an XML file (specified as the input File and returns it as a Document . |
static Document |
parseXML(URL url)
Parses an XML file (specified as the input URL and returns it as a Document . |
static String |
produceTextString(NodeList Nodes)
|
static void |
writeCollection(Writer out,
String indent,
String tag,
Collection<? extends XMLizable> elements)
|
static void |
writeCollection(Writer out,
String indent,
String bigTag,
Collection<String> elements,
String smallTag)
|
static void |
writeParameter(Writer out,
String indent,
String tag,
String value)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
xmlDir
public static final String xmlDir
- See Also:
- Constant Field Values
dtdDir
public static final String dtdDir
- See Also:
- Constant Field Values
xmlIndent
public static String xmlIndent
XMLUtils
public XMLUtils()
parseXML
public static Document parseXML(File file)
- Parses an XML file (specified as the input
File
and returns it as a Document
.
- Parameters:
file
- The File
that contains the XML document
- Returns:
- the parsed
Document
parseXML
public static Document parseXML(URL url)
- Parses an XML file (specified as the input
URL
and returns it as a Document
.
- Parameters:
url
- The URL
that contains the XML document
- Returns:
- the parsed
Document
existsElement
public static boolean existsElement(Element e,
String tagName)
getAttribute
public static String getAttribute(Element E,
String AttrName)
- Return an Element given an XML document, tag name, and index
- Parameters:
doc
- XML docuemnttagName
- a tag nameindex
- a index
- Returns:
- an Element
Unlike the Grok/Bean Factory (?) version, getElement's index does *NOT*
take nested elements into consideration...
getElement
public static Element getElement(Element E,
String TagName)
getElement
public static Element getElement(Element E,
String TagName,
int Index)
getSize
public static int getSize(Element E,
String TagName)
getDirectElementKids
public static List<Element> getDirectElementKids(Element E,
String TagName)
getDirectElementKids
public static List<Element> getDirectElementKids(Element E)
getSize
public static int getSize(Element E,
List TagNames)
getNamedChildren
public static List<Element> getNamedChildren(Element e,
List tags)
- New method which returns the direct children under e which have tags
listed under the List tags.
Thus, for example, given the element e:
w x y z
getNamedChildren(e,<"bar","ber">) should return the _elements_ (w,x,z)
- Parameters:
e
- tags
-
- Returns:
getTextValue
public static String getTextValue(Element E,
String TagName)
getTextValue
public static String getTextValue(Element E,
String TagName,
int Index)
getTextValue
public static String getTextValue(Element E)
produceTextString
public static String produceTextString(NodeList Nodes)
writeParameter
public static void writeParameter(Writer out,
String indent,
String tag,
String value)
throws IOException
- Throws:
IOException
writeCollection
public static void writeCollection(Writer out,
String indent,
String bigTag,
Collection<String> elements,
String smallTag)
throws IOException
- Throws:
IOException
writeCollection
public static void writeCollection(Writer out,
String indent,
String tag,
Collection<? extends XMLizable> elements)
throws IOException,
XMLException
- Throws:
IOException
XMLException