由于网上关于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对象的更多相关文章

  1. 【2017-05-03】winform打印控件、事件对象和事件数据、MDI窗体容器

    一.打印控件 第一步先把打印对象搞出来. - printDocument    打印对象(将要打印的内容放到该对象里,从该对象里取内容打印) 设置他的PrintPage事件(对于要打印的每一页触发一次 ...

  2. 发现日志文件和打印在eclipse控制台中的编码不一致

    发现日志文件和打印在eclipse控制台中的编码不一致,正好相反. 日志文件是用notepad打开的,notepad有自己的编码方式,查询编码为utf-8,日志文件汉字等等显示正常. 但是在eclip ...

  3. Java:IO流其他类(字节数组流、字符数组流、数据流、打印流、Properities、对象流、管道流、随机访问、序列流、字符串读写流)

    一.字节数组流: 类 ByteArrayInputStream:在构造函数的时候,需要接受数据源,而且数据源是一个字节数组. 包含一个内部缓冲区,该缓冲区包含从流中读取的字节.内部计数器跟踪 read ...

  4. 在eclipse中new 对象后怎么通过快捷键自动生成返回对象

    如题,每次new 对象的时候不想手动补全返回对象,可以实现快捷键生成返回对象.new  对象后可以按住ctrl+1,如下图: 选择第一行即可.

  5. 读取文本文件中的中文打印到Eclipse控制台为何显示问号

    原因:未将文本文件存为utf-8编码格式而是ascii编码格式.

  6. 如何使用Eclipse API 提供 org.eclipse.wst.wsdl 要解决阅读WSDL档?

    相对而言.Eclipse API中国的数据是比较小的.但Eclipse的API提供了许多的.非常强大. 实例,eclipse的Eclipse API 提供 org.eclipse.wst.wsdl包裹 ...

  7. 【java】打印一个对象即打印出该对象toString()返回值

    public class TestToString { public static void main(String[] args){ Node node1=new Node("东邪&quo ...

  8. java命令--jmap命令使用(查找内存泄漏对象)

    转自:https://www.cnblogs.com/kongzhongqijing/articles/3621163.html jdk安装后会自带一些小工具,jmap命令(Java Memory M ...

  9. 【Win 10 应用开发】打印UI元素

    Windows App支持将UI界面进行打印的功能,这与浏览器中的打印网页的用途相近,其好处就是“所见即所得”,直接把界面上呈现的内容打印下来,比重新创建打印图像方便得多. 要在通用App中实现打印, ...

随机推荐

  1. 基于visual Studio2013解决算法导论之046广度优先搜索

     题目 广度优先搜索 解决代码及点评 // 图的邻接表表示.cpp : 定义控制台应用程序的入口点. // #include <iostream> #include <stac ...

  2. Linux定义系统提示符的变量:PS1

  3. HDU 4883 TIANKENG’s restaurant (贪心)

    链接:pid=4883">带我学习.带我飞 第一次BC,稳挂,WA n多次.今天又一次做了一下 略挫 #include <iostream> #include <cs ...

  4. SimpleDateFormat使用具体解释

      public class SimpleDateFormat extends DateFormat SimpleDateFormat 是一个以国别敏感的方式格式化和分析数据的详细类. 它同意格式化 ...

  5. UNIX网络编程 卷2:进程间通信

    这篇是计算机类的优质预售推荐>>>><UNIX网络编程 卷2:进程间通信(第2版)> UNIX和网络专家W. Richard Stevens的传世之作 编辑推荐 两 ...

  6. cocos2d-x游戏开发系列教程-中国象棋02-main函数和欢迎页面

    之前两个博客讲述了象棋的规格和工程文件之后,我们继续深入的从代码开始学习cocos2dx 首先从程序入口main函数开始 main函数 int APIENTRY _tWinMain(HINSTANCE ...

  7. C# - Byte类型与String类型互转

    byte[] bs = Encoding.UTF8.GetBytes("你的字符串"); string str = Encoding.UTF8.GetString(bs);

  8. Ch02 从零开始实例学习4

    演练2-4  添加视图 原文链接:http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/adding-a-vi ...

  9. React.js学习

    React.js学习之环境搭建 1 工欲善其事必先利其器:前端开发工具 1.1 WebStorm和Sublime Text Sublime Text:作为代码编辑器,Sublime Text的优点如下 ...

  10. QObject,有一个生存线程(慢慢体会)

     moveToThread本来就是操作QObject的    比如把当前对象移到主线程里: myObject->moveToThread(QApplication::instance()-> ...