Printing Org.eclipse.xsd.XSDSchema Objects

Source: Internet
Author: User

Because there is less information about Eclipse XSD on the web, there are times when we need to construct or modify an XSD file using the Eclipse XSD API.

So when we create a Org.eclipse.xsd.XSDSchema object and have added or modified many of the element types in it, we want to know if our additions or modifications are valid.

So what should we do at this time? There are two ways to write the generated Org.eclipse.xsd.XSDSchema object into a file, and the other way is to direct the Xsdschema object

Turn into a string, and then print out the XSD of the Xsdschema code. Its code 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

Related Article

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.