打印org.eclipse.xsd.XSDSchema对象
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了打印org.eclipse.xsd.XSDSchema对象,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3164字,纯文字阅读大概需要5分钟。
内容图文
![打印org.eclipse.xsd.XSDSchema对象](/upload/InfoBanner/zyjiaocheng/1202/e5224dedfc5645fda6275ab53117bf14.jpg)
由于网上关于Eclipse XSD的中文资料比較少,可是有的时候。我们须要使用Eclipse XSD的API去构造或者改动一个XSD文件。
那么当我们创建了org.eclipse.xsd.XSDSchema的对象,并已经在里面加入或者改动很多的元素类型等信息后。我们想知道我们的加入或者改动是否有效。那么这个时候我们应该怎么办呢?
有两种方式,
(1)我们把生成的org.eclipse.xsd.XSDSchema的对象,写到一个文件中面去
(2)第二种方式就是直接把XSDSchema对象转成一个字符串,然后把XSDSchema代码的XSD打印出来。
在我们的代码调试过程中。当然是另外一种方式更为的方便和快捷。
其详细的代码方法例如以下:
import org.eclipse.xsd.XSDImport; import org.eclipse.xsd.XSDInclude; import org.eclipse.xsd.XSDRedefine; import org.eclipse.xsd.XSDSchema; import org.eclipse.xsd.XSDSchemaDirective; import org.eclipse.xsd.util.XSDResourceImpl; import org.w3c.dom.Element; public class SchemaPrintService { public static void printSchema(XSDSchema xsdSchema){ System.out.println("<!-- ===== Schema Composition ====="); 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>"); } }
原文:http://www.cnblogs.com/lcchuguo/p/5141629.html
内容总结
以上是互联网集市为您收集整理的打印org.eclipse.xsd.XSDSchema对象全部内容,希望文章能够帮你解决打印org.eclipse.xsd.XSDSchema对象所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。