类 UXml

java.lang.Object
com.gdxsoft.easyweb.utils.UXml

public class UXml extends Object
  • 构造器详细资料

    • UXml

      public UXml()
  • 方法详细资料

    • getElementAttributes

      public static Map<String,String> getElementAttributes(Element item, boolean keyToLower)
      Get XML Element all attributes
      参数:
      item - The element
      keyToLower - nodeName to lower case
      返回:
      Map <nodeName, nodeValue>
    • filterInvalidXMLcharacter

      public static String filterInvalidXMLcharacter(String xmlStr)
      过滤非法的字符 0x00 - 0x08 ,0x0b - 0x0c ,0x0e - 0x1f
      参数:
      xmlStr -
      返回:
      过滤后的xml
    • findNode

      public static Element findNode(Element fromNode, String findTag, String findAttr, String checkValue, boolean isIgnoreCase)
      从Xml中查找某个节点
      参数:
      fromNode -
      findTag - 要查找的TagName
      findAttr - 检查的属性名称
      checkValue - 检测值
      isIgnoreCase - 是否大小写匹配
      返回:
      节点
    • createXmlValue

      public static String createXmlValue(String s1)
      生成可Xml节点值
      参数:
      s1 -
      返回:
      节点值
    • retDocument

      public static Document retDocument(String xmlPath, boolean isAbsolutePath) throws ParserConfigurationException, SAXException, IOException
      读取文件,返回 Document
      参数:
      xmlPath - xml文件路径
      isAbsolutePath - 是否为绝对路径
      返回:
      document 对象
      抛出:
      ParserConfigurationException
      SAXException
      IOException
    • retDocument

      public static Document retDocument(String xmlPath) throws ParserConfigurationException, SAXException, IOException
      读取文件,返回 Document
      参数:
      xmlPath - xml文件路径
      返回:
      document 对象
      抛出:
      ParserConfigurationException
      SAXException
      IOException
    • saveDocument

      public static boolean saveDocument(Document document, String xmlFileName)
      save xml document to file
      参数:
      document - Document对象
      xmlFileName - 文件名
      返回:
      是否保存成功
    • saveDocument

      public static boolean saveDocument(Document document)
      将 Document对象保存为文件
      参数:
      document - Document对象
      返回:
      是否保存成功
    • retNodeValue

      public static String retNodeValue(Node node, String attName)
      返回属性值
      参数:
      node - 当前节点
      attName - 属性值
      返回:
      属性值
    • retNodeText

      public static String retNodeText(Node node)
      返回节点text
      参数:
      node - 当前节点
      返回:
      TextContent
    • retNodeList

      public static NodeList retNodeList(Document document, String tagName)
      返回下级节点集合
      参数:
      document - document对象
      tagName - 下级节点表达式,例如 aa/bb/cc,返回 aa<bb<cc
      返回:
      集合
    • retNodeList

      public static NodeList retNodeList(Node node, String tagName)
      返回下级节点集合
      参数:
      node - node 对象
      tagName - 下级节点表达式,例如 aa/bb/cc,返回 aa<bb<cc
      返回:
      集合
    • retNodeList

      public static NodeList retNodeList(Element element, String tagName)
      返回下级节点集合
      参数:
      element - element 对象
      tagName - 下级节点表达式,例如 aa/bb/cc,返回 aa<bb<cc
      返回:
      集合
    • retNode

      public static Node retNode(Node node, String tagName)
      返回下级节点
      参数:
      node - node对象
      tagName - 下级节点表达式,例如 aa/bb/cc,返回 aa<bb<cc
      返回:
      下级节点
    • retNode

      public static Node retNode(Document document, String tagName)
      返回下级节点
      参数:
      document -
      tagName - 下级节点表达式,例如 aa/bb/cc,返回 aa<bb<cc
      返回:
      下级节点
    • retNode

      public static Node retNode(Element element, String tagName)
      返回下级节点
      参数:
      element -
      tagName - 下级节点表达式,例如 aa/bb/cc,返回 aa<bb<cc
      返回:
      下级节点
    • retNodeListByPath

      public static NodeList retNodeListByPath(Element element, String tagPath)
      返回节点列表通过路径
      参数:
      element - element 元素
      tagPath - 下级节点表达式,例如 aa/bb/cc,返回 aa<bb<cc
      返回:
      列表
    • retNodeListByPath

      public static NodeList retNodeListByPath(Document document, String tagPath)
      返回节点列表通过路径
      参数:
      document - document对象
      tagPath - 下级节点表达式,例如 aa/bb/cc,返回 aa<bb<cc
      返回:
      列表
    • retNodeListByPath

      public static NodeList retNodeListByPath(Node node, String tagPath)
      返回节点列表通过路径
      参数:
      node - 父节点
      tagPath - 下级节点表达式,例如 aa/bb/cc,返回 aa<bb<cc
      返回:
      节点列表
    • addNode

      public static boolean addNode(Document document, Element newChilid, String tagPathParent)
      增加节点
      参数:
      document -
      newChilid -
      tagPathParent -
      返回:
      是否成功
    • removeNode

      public static boolean removeNode(Document document, String tagPath, String nodeAttribute, String attValue)
      删除节点
      参数:
      document -
      tagPath -
      nodeAttribute -
      attValue -
      返回:
      是否成功
    • queryNode

      public static Node queryNode(String xmlName, String itemName, String tagPath) throws ParserConfigurationException, SAXException, IOException
      获取配置文件的节点
      参数:
      xmlName - 文件路径
      itemName - 节点名称
      tagPath - 路径
      返回:
      节点
      抛出:
      IOException
      SAXException
      ParserConfigurationException
    • queryNode

      public static Node queryNode(Document document, String itemName, String tagPath)
      获取配置文件的节点
      参数:
      document - xml文档
      itemName - 节点名称
      tagPath - 路径
      返回:
      节点
    • queryNode

      public static Node queryNode(Document document, String attributeName, String itemName, String tagPath)
      获取配置文件的节点
      参数:
      document - xml文档
      attributeName - 属性名
      itemName - 节点名称
      tagPath - 路径
      返回:
      节点
    • asXml

      public static String asXml(Node node)
      返回Xml字符,不包含 <?xml version="1.0" encoding="UTF-8"?>
      参数:
      node - 节点
      返回:
      Xml字符串
    • asXmlPretty

      public static String asXmlPretty(Node node)
      美化Xml输出
      参数:
      node - 节点
      返回:
      Xml字符串
    • asXmlAll

      public static String asXmlAll(Node node)
      返回 Xml字符串 ,包含 <?xml version="1.0" encoding="UTF-8"?>
      参数:
      node -
      返回:
      Xml字符串
    • asNode

      public static Node asNode(String xmlSource)
      将xml字符串转换为 node
      参数:
      xmlSource -
      返回:
      node
    • getDocumentBuilder

      public static DocumentBuilderFactory getDocumentBuilder()
      获取安全的 DocumentBuilderFactory,避免XXE攻击
      返回:
      DocumentBuilderFactory
    • asDocument

      public static Document asDocument(String xmlSource)
      从xml字符串中返回XmlDocument对象
      参数:
      xmlSource - xml字符串
      返回:
      Document
    • createBlankDocument

      public static Document createBlankDocument()
      创建并返回空白的xml文档
      返回:
      Document
    • createSavedDocument

      public static Document createSavedDocument(String path, String rootTagName)
      生成空xml文档,并保存为文件
      参数:
      path - xml路径
      返回:
      xml文档
    • createBlankDocument

      public static Document createBlankDocument(String dtd, String qName)
      生成空文件
      参数:
      dtd - dtd文件
      qName - qName
      返回:
      Document
    • appendNode

      public static Document appendNode(Document sourceDocument, String nodeXmlString, String tagPath)
      在Xml文档中增加新的节点
      参数:
      sourceDocument - 源文档
      nodeXmlString - node的Xml字符
      tagPath - 增加的路径
      返回:
      新文档