edu.cmu.emulator.creator.util
Class Xml

java.lang.Object
  extended by edu.cmu.emulator.creator.util.Xml

public class Xml
extends Object


Constructor Summary
private Xml()
           
 
Method Summary
static Element createSimpleTag(Document doc, String name, String content)
          Create a tag called "name" which contains a text element "content." For example: <name>content</name>
static Element getSimpleEl(Element parent, String tag)
          Get an element within a parent.
static List<Element> getSimpleEls(Element parent, String tag)
          Get a list of children of the parent that have a given tag name.
static Element getSimpleElWithDefault(Element parent, String tag, Element def)
          Get an element within a parent.
static String getSimpleTag(Element parent, String tag)
          Get the content of a tag contained with a parent.
static String getSimpleTagWithDefault(Element parent, String tag, String def)
          Get the string contained within a tag of the given name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Xml

private Xml()
Method Detail

createSimpleTag

public static Element createSimpleTag(Document doc,
                                      String name,
                                      String content)
Create a tag called "name" which contains a text element "content." For example: <name>content</name>

Parameters:
doc - The XML document to use to create the tag.
name - The name of the wrapping tag.
content - The content to be placed into the tag.
Returns:
The XML tag element.

getSimpleEl

public static Element getSimpleEl(Element parent,
                                  String tag)
                           throws ConfigException
Get an element within a parent.

Parameters:
parent - The XML element holding the tag we are searching for.
tag - The tag we are searching for.
Returns:
The element with the matching tag name.
Throws:
ConfigException

getSimpleElWithDefault

public static Element getSimpleElWithDefault(Element parent,
                                             String tag,
                                             Element def)
Get an element within a parent. If the element does not exist, then return the given default value.

Parameters:
parent - The parent of the XML element we are searching for.
tag - The name of the tag we are searching for.
def - The value to return if the element could not be found.
Returns:
The (first) element found, or the default value if not found.

getSimpleEls

public static List<Element> getSimpleEls(Element parent,
                                         String tag)
Get a list of children of the parent that have a given tag name.

Parameters:
parent - The parent of the elements to search for.
tag - The tag of the elements to find.
Returns:
The list of all elements with the matching tag name.

getSimpleTag

public static String getSimpleTag(Element parent,
                                  String tag)
                           throws ConfigException
Get the content of a tag contained with a parent.

Parameters:
parent - The parent node, which contains the node we are searching for.
tag - The tag we want the content of.
Returns:
The content of the tag.
Throws:
ConfigException

getSimpleTagWithDefault

public static String getSimpleTagWithDefault(Element parent,
                                             String tag,
                                             String def)
Get the string contained within a tag of the given name. Return a default value if the element is not found.

Parameters:
parent - The parent of the tag to find.
tag - The name of the tag to find.
def - The default value to return if the given tag is not found.
Returns:
The string contained within the element, or the default value if none was found.


Copyright © 2013. All Rights Reserved.