类 XmlUtils

java.lang.Object
org.apache.velocity.tools.XmlUtils

public final class XmlUtils extends Object

Utility class for simplifying parsing of xml documents. Documents are not validated, and loading of external files (xinclude, external entities, DTDs, etc.) are disabled.

从以下版本开始:
3.0
版本:
$$
作者:
Claude Brisson
  • 方法详细资料

    • createDocumentBuilderFactory

      public static final DocumentBuilderFactory createDocumentBuilderFactory()
    • getAttribute

      public static String getAttribute(Node node, String attr, String def)
      Extracts an attribute from a node.
      参数:
      node - target node
      attr - attribute name
      def - default value
      返回:
      The value of the attribute, or def
    • getAttribute

      public static String getAttribute(Node node, String attr)
      参数:
      node - target node
      attr - attribute name
      返回:
      The value of the given attribute, or null if not present.
    • getBoolAttribute

      public static boolean getBoolAttribute(Node node, String attr, boolean def)
      Retrieves an attribute as a boolean.
      参数:
      node - target node
      attr - attribute name
      def - default value
      返回:
      True if the attribute exists and is not equal to "false" false if equal to "false", and def if not present.
    • getBoolAttribute

      public static boolean getBoolAttribute(Node node, String attr)
      参数:
      node - target node
      attr - attribute name
      返回:
      True if the attribute exists and is not equal to "false" false otherwise.
    • getIntAttribute

      public static int getIntAttribute(Node node, String attr, int def)
      参数:
      node - target node
      attr - attribute name
      def - default value
      返回:
      An attribute coerced to an integer.
    • getIntAttribute

      public static int getIntAttribute(Node node, String attr)
      参数:
      node - target node
      attr - attribute name
      返回:
      An attribute coerced to an integer.
    • parse

      public static Element parse(Reader xml)
      Attempts to parse the input xml into a single element.
      参数:
      xml - xml stream reader
      返回:
      The document object
    • parse

      public static Element parse(String xml)
      Attempts to parse the input xml into a single element.
      参数:
      xml - xml string
      返回:
      The document object
    • search

      public static NodeList search(String xpath, Node context) throws XPathExpressionException
      Search for nodes using an XPath expression
      参数:
      xpath - XPath expression
      context - evaluation context
      返回:
      org.w3c.NodeList of found nodes
      抛出:
      XPathExpressionException
    • getNodes

      public static List<Node> getNodes(String xpath, Node context) throws XPathExpressionException
      Search for nodes using an XPath expression
      参数:
      xpath - XPath expression
      context - evaluation context
      返回:
      List of found nodes
      抛出:
      XPathExpressionException
    • getElements

      public static List<Element> getElements(String xpath, Node context) throws XPathExpressionException
      Search for elements using an XPath expression
      参数:
      xpath - XPath expression
      context - evaluation context
      返回:
      List of found elements
      抛出:
      XPathExpressionException
    • nodePath

      public static String nodePath(Node n)

      Builds the xpath expression for a node (tries to use id/name nodes when possible to get a unique path)

      参数:
      n - target node
      返回:
      node xpath
    • nodeToString

      public static String nodeToString(Node node)
      XML Node to string
      参数:
      node - XML node
      返回:
      XML node string representation
    • isXmlMimeType

      public static boolean isXmlMimeType(String mimeType)
      Checkes whether the given mime type is an XML format
      参数:
      mimeType - mime type
      返回:
      true if this mime type is an XML format