Class XmlValidator
java.lang.Object
cloud.opencode.base.xml.validate.XmlValidator
XML Validator - XML well-formedness and validation utilities
XML 验证器 - XML 格式良好性和验证工具
This class provides static utilities for XML validation.
此类提供 XML 验证的静态工具。
Usage Examples | 使用示例:
// Check if XML is well-formed
boolean isWellFormed = XmlValidator.isWellFormed(xml);
// Validate well-formedness and get errors
ValidationResult result = XmlValidator.validateWellFormedness(xml);
// Validate against XSD schema
ValidationResult result = XmlValidator.validateSchema(xml, schemaPath);
// Validate against DTD
ValidationResult result = XmlValidator.validateDtd(xml, dtdPath);
Features | 主要功能:
- XML well-formedness validation - XML 格式良好性验证
- Schema and DTD validation delegation - Schema 和 DTD 验证委托
- Static utility methods for quick validation - 用于快速验证的静态工具方法
Security | 安全性:
- Thread-safe: Yes (stateless utility, secure parsing) - 线程安全: 是(无状态工具,安全解析)
- Null-safe: No (throws on null XML) - 空值安全: 否(null XML 抛异常)
- Since:
- JDK 25, opencode-base-xml V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic DtdValidatorCreates a DtdValidator.static booleanisValidAgainstSchema(String xml, Path schemaPath) Checks if XML is valid against a schema.static booleanisWellFormed(String xml) Checks if an XML string is well-formed.static booleanisWellFormed(Path path) Checks if an XML file is well-formed.static voidrequireWellFormed(String xml) Validates well-formedness and throws if invalid.static voidrequireWellFormed(Path path) Validates file well-formedness and throws if invalid.static SchemaValidatorschemaValidator(String schemaXml) Creates a SchemaValidator from schema string.static SchemaValidatorschemaValidator(Path schemaPath) Creates a SchemaValidator.static ValidationResultvalidateDtd(String xml) Validates XML with embedded DTD.static ValidationResultvalidateDtd(String xml, Path dtdPath) Validates XML against an external DTD.static ValidationResultvalidateDtd(Path xmlPath, Path dtdPath) Validates XML file against an external DTD.static ValidationResultvalidateSchema(XmlDocument document, Path schemaPath) Validates XmlDocument against an XSD schema.static ValidationResultvalidateSchema(String xml, String schemaXml) Validates XML against an XSD schema string.static ValidationResultvalidateSchema(String xml, Path schemaPath) Validates XML against an XSD schema.static ValidationResultvalidateSchema(Path xmlPath, Path schemaPath) Validates XML file against an XSD schema.static ValidationResultValidates XML well-formedness.static ValidationResultvalidateWellFormedness(Path path) Validates XML file well-formedness.
-
Method Details
-
isWellFormed
Checks if an XML string is well-formed. 检查 XML 字符串是否格式良好。- Parameters:
xml- the XML string | XML 字符串- Returns:
- true if well-formed | 如果格式良好则返回 true
-
isWellFormed
Checks if an XML file is well-formed. 检查 XML 文件是否格式良好。- Parameters:
path- the XML file path | XML 文件路径- Returns:
- true if well-formed | 如果格式良好则返回 true
-
validateWellFormedness
Validates XML well-formedness. 验证 XML 格式良好性。- Parameters:
xml- the XML string | XML 字符串- Returns:
- the validation result | 验证结果
-
validateWellFormedness
Validates XML file well-formedness. 验证 XML 文件格式良好性。- Parameters:
path- the XML file path | XML 文件路径- Returns:
- the validation result | 验证结果
-
requireWellFormed
Validates well-formedness and throws if invalid. 验证格式良好性,如果无效则抛出异常。- Parameters:
xml- the XML string | XML 字符串- Throws:
XmlValidationException- if not well-formed | 如果格式不良好则抛出
-
requireWellFormed
Validates file well-formedness and throws if invalid. 验证文件格式良好性,如果无效则抛出异常。- Parameters:
path- the XML file path | XML 文件路径- Throws:
XmlValidationException- if not well-formed | 如果格式不良好则抛出
-
validateSchema
Validates XML against an XSD schema. 针对 XSD 模式验证 XML。- Parameters:
xml- the XML string | XML 字符串schemaPath- the schema file path | 模式文件路径- Returns:
- the validation result | 验证结果
-
validateSchema
Validates XML against an XSD schema string. 针对 XSD 模式字符串验证 XML。- Parameters:
xml- the XML string | XML 字符串schemaXml- the XSD schema string | XSD 模式字符串- Returns:
- the validation result | 验证结果
-
validateSchema
Validates XML file against an XSD schema. 针对 XSD 模式验证 XML 文件。- Parameters:
xmlPath- the XML file path | XML 文件路径schemaPath- the schema file path | 模式文件路径- Returns:
- the validation result | 验证结果
-
validateSchema
Validates XmlDocument against an XSD schema. 针对 XSD 模式验证 XmlDocument。- Parameters:
document- the XML document | XML 文档schemaPath- the schema file path | 模式文件路径- Returns:
- the validation result | 验证结果
-
isValidAgainstSchema
-
validateDtd
Validates XML with embedded DTD. 验证带有嵌入式 DTD 的 XML。- Parameters:
xml- the XML string with DTD | 带 DTD 的 XML 字符串- Returns:
- the validation result | 验证结果
-
validateDtd
Validates XML against an external DTD. 针对外部 DTD 验证 XML。- Parameters:
xml- the XML string | XML 字符串dtdPath- the DTD file path | DTD 文件路径- Returns:
- the validation result | 验证结果
-
validateDtd
Validates XML file against an external DTD. 针对外部 DTD 验证 XML 文件。- Parameters:
xmlPath- the XML file path | XML 文件路径dtdPath- the DTD file path | DTD 文件路径- Returns:
- the validation result | 验证结果
-
schemaValidator
Creates a SchemaValidator. 创建 SchemaValidator。- Parameters:
schemaPath- the schema file path | 模式文件路径- Returns:
- a new SchemaValidator | 新的 SchemaValidator
-
schemaValidator
Creates a SchemaValidator from schema string. 从模式字符串创建 SchemaValidator。- Parameters:
schemaXml- the XSD schema string | XSD 模式字符串- Returns:
- a new SchemaValidator | 新的 SchemaValidator
-
dtdValidator
Creates a DtdValidator. 创建 DtdValidator。- Returns:
- a new DtdValidator | 新的 DtdValidator
-