类 Xml

java.lang.Object
com.darra.ethercat.utils.Xml

public class Xml extends Object
XML 配置工具类 对应 C# Utils/Xml.cs 提供 ENI/DENI 配置文件的导入/导出功能
  • 字段详细资料

  • 方法详细资料

    • parseIntHexOrDec

      public static int parseIntHexOrDec(String s)
      解析 uint, 支持 "0x" 或 "#" 前缀的十六进制, 也支持十进制
      参数:
      s - 字符串
      返回:
      解析结果, 失败返回 0
    • parseShortHexOrDec

      public static short parseShortHexOrDec(String s)
      解析 short, 采用与 parseIntHexOrDec 相同的规则
    • parseByteHexOrDec

      public static byte parseByteHexOrDec(String s)
      解析 byte, 支持十六进制或十进制字符串
    • parseXmlFile

      public static Document parseXmlFile(String filePath)
      解析 XML 文件
      参数:
      filePath - 文件路径
      返回:
      Document 对象, 失败返回 null
    • parseXmlString

      public static Document parseXmlString(String xml)
      解析 XML 字符串
      参数:
      xml - XML 字符串
      返回:
      Document 对象, 失败返回 null
    • findChildIgnoreCase

      public static Element findChildIgnoreCase(Element parent, String name)
      按名称 (忽略大小写) 查找第一个子元素
    • getAttributeIgnoreCase

      public static String getAttributeIgnoreCase(Element el, String name)
      按名称 (忽略大小写) 获取属性值
    • writeXmlFile

      public static boolean writeXmlFile(Document doc, String filePath)
      将 Document 写入文件
      参数:
      doc - Document 对象
      filePath - 输出文件路径
      返回:
      成功返回 true
    • documentToString

      public static String documentToString(Document doc)
      将 Document 转换为字符串
      参数:
      doc - Document 对象
      返回:
      XML 字符串
    • parseHexStringFlexible

      public static byte[] parseHexStringFlexible(String hex)
      解析灵活的十六进制字符串, 支持可选的 0x 或 # 前缀
      参数:
      hex - 十六进制字符串
      返回:
      字节数组, 失败返回空数组
    • ApplyXMLConfiguration

      public static boolean ApplyXMLConfiguration(Xml.MasterXMLConfiguration config, EtherCATMaster master)
      将 XML 配置应用到主站 (对应 C# ApplyXMLConfiguration)
      参数:
      config - 已加载的 XML 配置
      master - 主站实例
      返回:
      是否成功