Package yearreview.app.util.xml
Class XmlNode
java.lang.Object
yearreview.app.util.xml.XmlNode
A Wrapper around a
node that allows for easier access of child nodes.- Author:
- ColdStone37
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidassertAttributesExist(String... attributes) Makes sure that this node has certain attributes.voidassertChildNodesExist(String... children) Makes sure that this node has certain children.getAttributeByName(String name) Gets an attribute by its name.getChildByName(String name) Gets a child of this node by name.getChildContent(String name) Gets text content of a child node directly.getName()Gets the Name of the Node.Gets the text content of a node.booleanTests whether a child node exists.iterator()Gets an Iterator for the children contained in the node.static XmlNodeparseXmlFile(File f) Parses a given XML-file and return the root-XmlNode.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
node
The node that is wrapped by this object. -
nameToNodeMap
A Map used to convert the name of a child to its node directly.
-
-
Constructor Details
-
XmlNode
Constructs a ConfigNode from aNode.- Parameters:
node- the node to create the ConfigNode from
-
-
Method Details
-
getName
Gets the Name of the Node. (Wrapper forNode.getNodeName())- Returns:
- name of the node
-
getChildByName
Gets a child of this node by name.- Parameters:
name- name of the node to get- Returns:
- child with given name or null if such a node doesn't exists
-
getChildContent
Gets text content of a child node directly.- Parameters:
name- name of the node to get the text content from- Returns:
- text content of the child node with the given name
-
hasChild
Tests whether a child node exists.- Parameters:
name- name of the child node to test for- Returns:
- true if the node exists, false otherwise
-
getTextContent
Gets the text content of a node. (Wrapper forNode.getTextContent())- Returns:
- text content of this node
-
getAttributeByName
Gets an attribute by its name.- Parameters:
name- name of the attribute to get- Returns:
- Value of the attribute or null if the attribute doesn't exist
-
assertChildNodesExist
Makes sure that this node has certain children. If one or more of them don't exist an error is thrown.- Parameters:
children- the children that must exist
-
assertAttributesExist
Makes sure that this node has certain attributes. If one or more of them don't exist an error is thrown.- Parameters:
attributes- the attributes that must exist
-
iterator
Gets an Iterator for the children contained in the node. Internally aArrayListof ConfigNodes is created and it's iterator gets returned. -
parseXmlFile
public static XmlNode parseXmlFile(File f) throws IOException, ParserConfigurationException, SAXException Parses a given XML-file and return the root-XmlNode.- Parameters:
f- file to parse- Returns:
- root-node of the XML-file
- Throws:
IOException- if the file cannot be loadedParserConfigurationException- if the parsed was not configured correctlySAXException- If the file cannot be parsed
-