打印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中实现打印, ...
随机推荐
- MVC中Controller里写alert的问题
controller: Viewbag.a=true; 页面中 @if(Viewbag.a!=null) { <script> alert('XXX'); </script> ...
- Codeforces Round #312 (Div. 2)
好吧,再一次被水题虐了. A. Lala Land and Apple Trees 敲码小技巧:故意添加两个苹果树(-1000000000, 0)和(1000000000, 0)(前者是位置,后者是价 ...
- eclipse、MyEclipse实现批量改动文件编码
在使用eclipse或MyEclipse编程时,常常遇到部分文件打开后出现乱码的情况(特别是在导入项目后) 1:右击项目选择properties->Resource>Other选择UTF- ...
- Android中如何查看内存(下)
实例1 int cnt=0; final static int kBufferMinSize=1000; final static int kBufferMaxSize=2000; StringBuf ...
- 往Amazon上upload bundle经常中断的处理方法
首先可以按如下脚本进行重复提交 #!/bin/bash ;i<=;i=i+)) do ret1=`bin/ec2-upload-bundle -b myrawbucket -m /ec2-ami ...
- 最新Cocos2d-x3.2开发环境搭建(windows环境下)
原文地址:http://cache.baiducontent.com/c?m=9d78d513d9921cfe05ac837f7d16c067690297634d9dc7150ed58449e3735 ...
- Qt核心剖析:信息隐藏(三篇)
http://devbean.blog.51cto.com/448512/335550 http://devbean.blog.51cto.com/448512/325581 http://devbe ...
- codeforces 264D Colorful Stones
题目 题目来自于rng_58Orz. 算法 讨论某个状态\((x,y)\)是否可达,\(x\)是狐狸到达的石头,\(y\)是猫的. 题解说,如果满足以下条件,那么它就是可到达状态: \(t[0..y] ...
- 《高质量程序设计指南:C++/C语言》面试题整理
本试题仅用于考查C++/C程序员的基本编程技能.内容限于C++/C常用 语法,不涉及 数据结构. 算法以及深奥的语法.考试成绩能反映出考生的编程质量以及对C++/C的理解程度,但不能反映考生的智力和软 ...
- hdu 3917 (最大权闭合图)
题意:政府有一些路,m个公司来修,每个公司修路要交税给政府,修路政府要付给公司费用,求政府能获得的最大利润,如果选择一个公司负责一个项目,那么该公司负责的其它项目也必须由他负责,并且与其有相连关系的公 ...