Class SchemaValidator
java.lang.Object
cloud.opencode.base.xml.validate.SchemaValidator
Schema Validator - XML Schema (XSD) validation
Schema 验证器 - XML Schema (XSD) 验证
This class provides XML validation against XSD schemas.
此类提供针对 XSD 模式的 XML 验证。
Usage Examples | 使用示例:
// Validate XML against schema
ValidationResult result = SchemaValidator.of(schemaPath)
.validate(xml);
if (!result.isValid()) {
System.err.println(result.getErrorSummary());
}
// Validate and throw on error
SchemaValidator.of(schemaPath)
.validateOrThrow(xml);
Features | 主要功能:
- XML Schema (XSD) validation - XML Schema(XSD)验证
- Validate from string, file, or input stream - 从字符串、文件或输入流验证
- Detailed error and warning collection - 详细的错误和警告收集
- Since:
- JDK 25, opencode-base-xml V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionGets the underlying Schema.booleanisValid(XmlDocument document) Checks if an XmlDocument is valid.booleanChecks if an XML string is valid.static SchemaValidatorof(InputStream input) Creates a validator from a schema input stream.static SchemaValidatorCreates a validator from a schema string.static SchemaValidatorCreates a validator from a schema file.static SchemaValidatorCreates a validator from multiple schema sources.validate(XmlDocument document) Validates an XmlDocument.validate(InputStream input) Validates an XML input stream.Validates an XML string.Validates an XML file.Validates from a Source.voidvalidateOrThrow(XmlDocument document) Validates and throws if invalid.voidvalidateOrThrow(String xml) Validates and throws if invalid.voidvalidateOrThrow(Path path) Validates and throws if invalid.
-
Method Details
-
of
Creates a validator from a schema file. 从模式文件创建验证器。- Parameters:
schemaPath- the schema file path | 模式文件路径- Returns:
- a new validator | 新验证器
-
of
Creates a validator from a schema string. 从模式字符串创建验证器。- Parameters:
schemaXml- the XSD schema string | XSD 模式字符串- Returns:
- a new validator | 新验证器
-
of
Creates a validator from a schema input stream. 从模式输入流创建验证器。- Parameters:
input- the schema input stream | 模式输入流- Returns:
- a new validator | 新验证器
-
of
Creates a validator from multiple schema sources. 从多个模式源创建验证器。- Parameters:
sources- the schema sources | 模式源- Returns:
- a new validator | 新验证器
-
validate
Validates an XML string. 验证 XML 字符串。- Parameters:
xml- the XML string | XML 字符串- Returns:
- the validation result | 验证结果
-
validate
Validates an XmlDocument. 验证 XmlDocument。- Parameters:
document- the XML document | XML 文档- Returns:
- the validation result | 验证结果
-
validate
Validates an XML file. 验证 XML 文件。- Parameters:
path- the XML file path | XML 文件路径- Returns:
- the validation result | 验证结果
-
validate
Validates an XML input stream. 验证 XML 输入流。- Parameters:
input- the XML input stream | XML 输入流- Returns:
- the validation result | 验证结果
-
validate
Validates from a Source. 从 Source 验证。- Parameters:
source- the XML source | XML 源- Returns:
- the validation result | 验证结果
-
validateOrThrow
Validates and throws if invalid. 验证,如果无效则抛出异常。- Parameters:
xml- the XML string | XML 字符串- Throws:
XmlValidationException- if validation fails | 如果验证失败则抛出
-
validateOrThrow
Validates and throws if invalid. 验证,如果无效则抛出异常。- Parameters:
document- the XML document | XML 文档- Throws:
XmlValidationException- if validation fails | 如果验证失败则抛出
-
validateOrThrow
Validates and throws if invalid. 验证,如果无效则抛出异常。- Parameters:
path- the XML file path | XML 文件路径- Throws:
XmlValidationException- if validation fails | 如果验证失败则抛出
-
isValid
Checks if an XML string is valid. 检查 XML 字符串是否有效。- Parameters:
xml- the XML string | XML 字符串- Returns:
- true if valid | 如果有效则返回 true
-
isValid
Checks if an XmlDocument is valid. 检查 XmlDocument 是否有效。- Parameters:
document- the XML document | XML 文档- Returns:
- true if valid | 如果有效则返回 true
-
getSchema
-