程序包 com.ajaxjs.util

类 XmlHelper

java.lang.Object
com.ajaxjs.util.XmlHelper

public class XmlHelper extends Object
XML 处理工具类 ...
作者:
sp42 [email protected]
  • 构造器详细资料

    • XmlHelper

      public XmlHelper()
  • 方法详细资料

    • initBuilder

      public static DocumentBuilder initBuilder()
      XML 转换需要的对象
      返回:
      XML 转换需要的对象
    • xPath

      public static void xPath(String xml, String xpath, Consumer<Node> fn)
      获取某个节点
      参数:
      xml - XML 文件路径
      xpath - XPath 路径
      fn - 处理节点的函数,传入 Node 类型节点
    • parseXML

      public static void parseXML(String xml, BiConsumer<Node,NodeList> fn)
      解析 XML
      参数:
      xml - XML 内容
      fn - 处理节点的函数,传入 Element 类型节点和 NodeList 类型子元素列表
    • getRoot

      public static Element getRoot(String xml)
      根据给定的 XML 字符串获取根元素
      参数:
      xml - XML字符串
      返回:
      根元素
    • nodeAsMap

      public static Map<String,String> nodeAsMap(String xml, String xpath)
      将节点所有属性都转换为 map
      参数:
      xml - XML 文件路径
      xpath - XPath 路径
      返回:
      节点 map
    • getNodeText

      public static String getNodeText(Node node)
      获取节点内的文本内容,包括标签
      参数:
      node - 节点对象
      返回:
      innerBody
    • getNodeAttribute

      public static String getNodeAttribute(Node node, String attrName)
      获取节点属性值
      参数:
      node - 节点对象
      attrName - 属性名称
      返回:
      属性值,如果空返回 null
    • getAttribute

      public static String getAttribute(Node el, String attrName)
      获取指定的 attribute 值
      参数:
      el - 节点
      attrName - 属性名
      返回:
      属性值