打印org.eclipse.xsd.XSDSchema对象
由于网上关于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>");
} }
打印org.eclipse.xsd.XSDSchema对象的更多相关文章
- 【2017-05-03】winform打印控件、事件对象和事件数据、MDI窗体容器
一.打印控件 第一步先把打印对象搞出来. - printDocument 打印对象(将要打印的内容放到该对象里,从该对象里取内容打印) 设置他的PrintPage事件(对于要打印的每一页触发一次 ...
- 发现日志文件和打印在eclipse控制台中的编码不一致
发现日志文件和打印在eclipse控制台中的编码不一致,正好相反. 日志文件是用notepad打开的,notepad有自己的编码方式,查询编码为utf-8,日志文件汉字等等显示正常. 但是在eclip ...
- Java:IO流其他类(字节数组流、字符数组流、数据流、打印流、Properities、对象流、管道流、随机访问、序列流、字符串读写流)
一.字节数组流: 类 ByteArrayInputStream:在构造函数的时候,需要接受数据源,而且数据源是一个字节数组. 包含一个内部缓冲区,该缓冲区包含从流中读取的字节.内部计数器跟踪 read ...
- 在eclipse中new 对象后怎么通过快捷键自动生成返回对象
如题,每次new 对象的时候不想手动补全返回对象,可以实现快捷键生成返回对象.new 对象后可以按住ctrl+1,如下图: 选择第一行即可.
- 读取文本文件中的中文打印到Eclipse控制台为何显示问号
原因:未将文本文件存为utf-8编码格式而是ascii编码格式.
- 如何使用Eclipse API 提供 org.eclipse.wst.wsdl 要解决阅读WSDL档?
相对而言.Eclipse API中国的数据是比较小的.但Eclipse的API提供了许多的.非常强大. 实例,eclipse的Eclipse API 提供 org.eclipse.wst.wsdl包裹 ...
- 【java】打印一个对象即打印出该对象toString()返回值
public class TestToString { public static void main(String[] args){ Node node1=new Node("东邪&quo ...
- java命令--jmap命令使用(查找内存泄漏对象)
转自:https://www.cnblogs.com/kongzhongqijing/articles/3621163.html jdk安装后会自带一些小工具,jmap命令(Java Memory M ...
- 【Win 10 应用开发】打印UI元素
Windows App支持将UI界面进行打印的功能,这与浏览器中的打印网页的用途相近,其好处就是“所见即所得”,直接把界面上呈现的内容打印下来,比重新创建打印图像方便得多. 要在通用App中实现打印, ...
随机推荐
- c语言‘\0’ ,‘0’, “0” ,0之间的区别
首先比较一下‘\0’和‘0’的区别.有一个共同点就是它们都是字符,在c语言中,字符是按其所对应的ASCII码来存储的,一个字符占一个字节.请翻开你的ASCII字符集表吧,一般在你的C语言教材的附录上, ...
- 已知的CPropertysheet bug: 切换焦点导致无响应
当一个页面内容比较多时我们首先可能考虑用Tab Control,但如果有很多页面内容需要动态加载则用CPropertySheet比较好点~ CPropertySheet有两种不同的显示模式.一种就是向 ...
- WPF-22:WPF绘制五角星改进版(增加半个五角星的绘制)-修改bug
之前用坐标画多边形的方法,绘制五角星.今天调试时发现当时写的时候有bug,修改一下. 原文: http://blog.csdn.net/yysyangyangyangshan/article/deta ...
- SQL基础使用
result = executeQuery(“ SELECT FName, FSalary FROM T_Employee ”); for(i=0;i<result.count;i++) { s ...
- 五、Nginx多Server反向代理配置
Nginx强大的正则表达式支持,可以使server_name的配置变得很灵活,如果你要做多用户博客,那么每个用户拥有自己的二级域名也就很容易实现了. server_name的匹配顺序 Nginx中的s ...
- Android 应用程序签名
本文主要介绍Android应用程序签名的相关理论知识以及怎样公布Android应用程序. 1.签名的概念 为大家所熟知的日常生活中的签名,它是代表某个人的特殊标记,用于唯一标识某个人.而Android ...
- javascript每日一练(三)——DOM一
一.Dom基础 childNodes(有兼容问题),children nodeType getAttribute() firstChild,lastChild,previousSilbing,next ...
- c++中一个类所占用的空间
看到阿里的一道笔试题: #pragma pack(2) class A { int i; union U { char buff[13]; int i; }u; void foo() { } type ...
- 学习算法-基数排序(radix sort)卡片分类(card sort) C++数组实现
基数排序称为卡片分类,这是一个比较早的时间越多,排名方法. 现代计算机出现之前,它已被用于排序老式打孔卡. 说下基数排序的思想.前面我有写一个桶式排序,基数排序的思想是桶式排序的推广. 桶式排序:ht ...
- MSSQL - 存储过程取出5条热点新闻
USE [DB_News] GO /****** Object: StoredProcedure [dbo].[SelectHotNews] Script Date: 2015/7/8 13:34:4 ...