Class XMLUtil

java.lang.Object
games.stendhal.server.core.config.XMLUtil

public class XMLUtil extends Object
XML utility methods for DOM reading.
  • Constructor Details

    • XMLUtil

      public XMLUtil()
  • Method Details

    • getElements

      public static List<Element> getElements(Element parent)
      Get all the direct children elements of an element.
      Parameters:
      parent - The parent element.
      Returns:
      A list of Element's.
    • getElements

      public static List<Element> getElements(Element parent, String name)
      Get all the direct children elements of an element that have a specific tag name.
      Parameters:
      parent - The parent element.
      name - The tag name to match.
      Returns:
      A list of Element's.
    • getElement

      public static Element getElement(Element parent, String name)
      Retrieve first element found.
    • getText

      public static String getText(Element element)
      Get the direct text content of an element.
      Parameters:
      element - The element.
      Returns:
      The contained text.
    • getText

      public static void getText(Element element, StringBuilder sbuf, boolean decend)
      Get the text content of an element.
      Parameters:
      element - The element.
      sbuf - The buffer to append to.
      decend - Whether to descend into child elements.
    • createChildElement

      public static Element createChildElement(Element parent, String name, List<String> order)
      creates a child element at the specified position
      Parameters:
      parent - parent element
      name - name of new child element
      order - order of elements to insert the new child element at the correct position
      Returns:
      newly created child element
    • parse

      public static Document parse(InputStream in) throws SAXException, IOException
      Parse an XML document.
      Parameters:
      in - The input stream.
      Returns:
      A Document.
      Throws:
      SAXException - If there is a parsing error.
      IOException - If there is an I/O error.
      IllegalArgumentException - If there is a parser configuration error.
    • parse

      public static Document parse(InputSource is) throws SAXException, IOException
      Parse an XML document.
      Parameters:
      is - The input source.
      Returns:
      A Document.
      Throws:
      SAXException - If there is a parsing error.
      IOException - If there is an I/O error.
      IllegalArgumentException - If there is a parser configuration error.
    • writeFile

      public static void writeFile(Document document, String filename) throws IOException, TransformerException
      writes an xml document to a file
      Parameters:
      document - DOM document
      filename - filename
      Throws:
      IOException - in case of an input/output error
      TransformerException - in case of an transformation issue
    • checkCondition

      public static boolean checkCondition(String condition)
      checks if a condition is true
      Parameters:
      condition - value of the condition attribute
      Returns:
      result of the evaluation of the condition