Eclipse XSD 生成枚举类型的Schema的实例详解
前言:
因为网上关于Eclipse XSD的中文资料比较少,而且关于Eclipse XSD的范例代码也凤毛麟角,但是有的时候我们需要生成一个带枚举限定的简单类型的XSD Schema,比如下面的格式,
<?xml version="1.0" encoding="UTF-8"?><schema xmlns="http://position ====="); printDirectives(" ", xsdSchema); System.out.println("-->"); System.out .println("<!-- [ " + xsdSchema.getSchemaLocation() + " ] -->"); xsdSchema.updateElement(); Element element = xsdSchema.getElement(); if (element != null) { // Print the serialization of the model. XSDResourceImpl.serialize(System.out, element); } } private static void printSchemaStart(XSDSchema xsdSchema) { System.out.print("<schema targetNamespace=\""); if (xsdSchema.getTargetNamespace() != null) { System.out.print(xsdSchema.getTargetNamespace()); } System.out.print("\" schemaLocation=\""); if (xsdSchema.getSchemaLocation() != null) { System.out.print(xsdSchema.getSchemaLocation()); } System.out.print("\">"); } private static void printDirectives(String indent, XSDSchema xsdSchema) { System.out.print(indent); printSchemaStart(xsdSchema); System.out.println(); if (!xsdSchema.getReferencingDirectives().isEmpty()) { System.out.println(indent + " <referencingDirectives>"); for (XSDSchemaDirective xsdSchemaDirective : xsdSchema .getReferencingDirectives()) { XSDSchema referencingSchema = xsdSchemaDirective.getSchema(); System.out.print(indent + " "); printSchemaStart(referencingSchema); System.out.println(); System.out.print(indent + " "); if (xsdSchemaDirective instanceof XSDImport) { XSDImport xsdImport = (XSDImport) xsdSchemaDirective; System.out.print("<import namespace=\""); if (xsdImport.getNamespace() != null) { System.out.print(xsdImport.getNamespace()); } System.out.print("\" schemaLocation=\""); } else if (xsdSchemaDirective instanceof XSDRedefine) { System.out.print("<redefine schemaLocation=\""); } else if (xsdSchemaDirective instanceof XSDInclude) { System.out.print("<include schemaLocation=\""); } if (xsdSchemaDirective.getSchemaLocation() != null) { System.out.print(xsdSchemaDirective.getSchemaLocation()); } System.out.println("\"/>"); System.out.println(indent + " </schema>"); } System.out.println(indent + " </referencingDirectives>"); } if (!xsdSchema.getIncorporatedVersions().isEmpty()) { System.out.println(indent + " <incorporatedVersions>"); for (XSDSchema incorporatedVersion : xsdSchema .getIncorporatedVersions()) { printDirectives(indent + " ", incorporatedVersion); } System.out.println(indent + " </incorporatedVersions>"); } System.out.println(indent + "</schema>"); } }
如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!