Printing Org.eclipse.xsd.XSDSchema Objects

Source: Internet
Author: User

Because the online information about Eclipse XSD is relatively small in Chinese, but sometimes. We need to use the Eclipse XSD API to construct or alter an XSD file.

So when we create a Org.eclipse.xsd.XSDSchema object and have added or changed many of the element types, etc. We would like to know if our affiliation or change is valid. So what should we do at this time?

There are two ways of

(1) We put the generated Org.eclipse.xsd.XSDSchema object, write to a file in the face to

(2) The second way is to directly convert the Xsdschema object into a string and then print out the XSD of the Xsdschema code.

During the debugging of our code. Of course, the other way is more convenient and fast.

Its detailed code method is as follows:

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);p Rintschemastart ( 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 + "");p Rintschemastart (Referencingschema); System.out.println (); System.out.print (Indent + ""); if (xsdschemadirective instanceof xsdimport) {xsdimport Xsdimport = (xsdimport) Xsdsch emadirective; System.out.print ("<import namespace=\"); if (Xsdimport.getnamespace ()! = null) {System.out.print ( Xsdimport.getnamespace ());} System.out.print ("\" schemalocation=\ "");} else if (xsdschemadirective instanceofXsdredefine) {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 + "", Incorporatedve rsion);} System.out.println (indent + "</incorporatedVersions>");} System.out.println (indent + "</schema>");}}


Printing Org.eclipse.xsd.XSDSchema Objects

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.