由于网上关于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. Windows Phone 8初学者开发—第18部分:在页面间导航

    原文 Windows Phone 8初学者开发—第18部分:在页面间导航 原文地址:  http://channel9.msdn.com/Series/Windows-Phone-8-Developm ...

  2. BT基础知识简介

    1. 蓝牙概述   无线局域网的通信 适用范围:10米到100米(根据发射功率的class不同有所差别,典型的class2为10m,而class1为100m,class3为1m) 应用:   局域网络 ...

  3. [转]使用xftp连接centos6.5

    首先要在windows上安装xftp软件,这个是傻瓜式操作就不说了 安装完成之后,在centos上查看是否装了xftpd服务,[root@centos Desktop]# rpm -qa | grep ...

  4. IOS SWIFT UITableView 实现简单微博列表

    // // Weibo.swift // UITableViewCellExample // // Created by XUYAN on 15/8/15. // Copyright (c) 2015 ...

  5. 重设mysql数据库root用户密码

     原文:http://blog.sina.com.cn/s/blog_a3695da601010mrs.html   1, 启用任务管理器,结束mysql进程   2,进入命令行,进入mysql的bi ...

  6. vi 快捷键积累

    依据自己用到的.或者还没记住的.或者用的时候忘了的,慢慢积累. 一.全选复制粘贴. 全选: ggVG // 凝视: gg 光标移到首行 V 进入Visual(可视)模式 G 光标移到最后一行全选 选中 ...

  7. c#基础练习之if结构

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace if语句 ...

  8. 使Web Api 支持跨域资源共享(CORS)

    Reference:http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api Imp ...

  9. encode_utf8 把字符编码成字节 微信例子

    ##µ¼Èë encode_json decode_json use JSON qw/encode_json decode_json/; print "1111111111111111-\$ ...

  10. teamviewer无法启动

    在 Linux.Mac OS X和 Windows下都可以用,但在 Linux 下无法启动时怎么办? 笔者回家工作时,都会用 Teamviewer 连线到其他 Linux 桌面,但某天起 Teamvi ...