比如以下XML文件配置的内容,可以由以下类相应的具体实例来表达
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xsi="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <groupId>com.dslztx</groupId> <artifactId>parent</artifactId> <version>1.0-SNAPSHOT</version> </parent> </project>>
class Equivalent { String xmlns; String xsi; String schemaLocation; Parent parent; } class Parent { String groupId; String artifactId; String version; } public class Main { public static void main(String[] args) { Equivalent equivalent = new Equivalent(); equivalent.xmlns = "http://maven.apache.org/POM/4.0.0"; equivalent.xsi = "http://www.w3.org/2001/XMLSchema-instance"; equivalent.schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"; Parent parent = new Parent(); parent.groupId = "com.dslztx"; parent.artifactId = "parent"; parent.version = "1.0-SNAPSHOT"; equivalent.parent = parent; } }有些XML文件引入XSD文件来限定XML文件中能够配置的内容,那么获取XML文件的等价类可以通过分析XSD文件得到