Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » XML Schema Definition (XSD) » Serialize XSD Object(Serialize XSD Object having <xs:include> tags )
Serialize XSD Object [message #764951] Tue, 13 December 2011 01:45 Go to next message
Manu  is currently offline Manu
Messages: 7
Registered: November 2009
Junior Member
I have a object of org.eclipse.xsd.impl.XSDSchemaImpl class of a xsd schema [say A.xsd]. This schema has some <xs:include> tags for including other supporting schemas [say B.xsd and C.xsd]. Now I want to convert this XSDSchemaImpl object into a String such that it include all the element definitions which are defined in the supporting included schema [i.e in B.xsd and C.xsd] will be part of this string. I tried it this way but it gives me only A.xsd in the String.
public Writer writeSchema(XSDSchema schema) throws IOException {
    if (schema == null){
        return;
    }
    URI schemaUri = URI.createFileURI("");
    Resource resource = new XSDResourceFactoryImpl().createResource(schemaUri);
    resource.getContents().add(schema);
    XSDResourceImpl xsdResource = (XSDResourceImpl) resource;
            Writer strWriter = new StringWriter();
    try {
        xsdResource.save(writer, null);
    } finally {
        xsdResource.unload();
    }
            return strWriter ;
}
Re: Serialize XSD Object [message #764997 is a reply to message #764951] Tue, 13 December 2011 03:36 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25910
Registered: July 2009
Senior Member
Manu,

You'll need to actually transform the model into a single schema
instance to get that kind of result. That's not always easy, even just
using DOM, because there could well be conflicting namespace declarations...


On 13/12/2011 7:45 AM, Manu wrote:
> I have a object of org.eclipse.xsd.impl.XSDSchemaImpl class of a xsd
> schema [say A.xsd]. This schema has some <xs:include> tags for
> including other supporting schemas [say B.xsd and C.xsd]. Now I want
> to convert this XSDSchemaImpl object into a String such that it
> include all the element definitions which are defined in the
> supporting included schema [i.e in B.xsd and C.xsd] will be part of
> this string. I tried it this way but it gives me only A.xsd in the
> String.
> public Writer writeSchema(XSDSchema schema) throws IOException {
> if (schema == null){
> return;
> }
> URI schemaUri = URI.createFileURI("");
> Resource resource = new
> XSDResourceFactoryImpl().createResource(schemaUri);
> resource.getContents().add(schema);
> XSDResourceImpl xsdResource = (XSDResourceImpl) resource;
> Writer strWriter = new StringWriter();
> try {
> xsdResource.save(writer, null);
> } finally {
> xsdResource.unload();
> }
> return strWriter ;
> }
Re: Serialize XSD Object [message #765037 is a reply to message #764997] Tue, 13 December 2011 05:03 Go to previous messageGo to next message
Manu  is currently offline Manu
Messages: 7
Registered: November 2009
Junior Member
Hi Merks

thanks very much for the quick reply. I completely understood the risk of conflicting namespace declarations. My application don't have any such use case. Can you please guide me that what I need to do to transform the model into a single schema
instance to get that kind of result.
Please let me know if you need any other details.
Re: Serialize XSD Object [message #765048 is a reply to message #765037] Tue, 13 December 2011 05:20 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25910
Registered: July 2009
Senior Member
Manu,

Is this something you need to do repeatedly or is there just a single
schema for which you need this? What have you tried so far?


On 13/12/2011 11:04 AM, Manu wrote:
> Hi Merks
>
> thanks very much for the quick reply. I completely understood the risk
> of conflicting namespace declarations. My application don't have any
> such use case. Can you please guide me that what I need to do to
> transform the model into a single schema instance to get that kind of
> result. Please let me know if you need any other details.
>
Re: Serialize XSD Object [message #765070 is a reply to message #765048] Tue, 13 December 2011 06:08 Go to previous messageGo to next message
Manu  is currently offline Manu
Messages: 7
Registered: November 2009
Junior Member
Merks,

I need to do this repeatedly in my application. I also can't merge all the xsd's into one single xsd as it will create lots of duplication and maintenance problem.I have not tried any thing yet as I am not aware of any way by which I can generate one xsd from multiple xsd'd.If you can provide me any pointer that will be great help for me.
Re: Serialize XSD Object [message #765090 is a reply to message #765070] Tue, 13 December 2011 06:50 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 25910
Registered: July 2009
Senior Member
XSDPrototypicalSchema has some good examples. The idea would be to
copy/move the contents of the included schema to the including schema.


On 13/12/2011 12:08 PM, Manu wrote:
> Merks,
>
> I need to do this repeatedly in my application. I also can't merge all
> the xsd's into one single xsd as it will create lots of duplication
> and maintenance problem.I have not tried any thing yet as I am not
> aware of any way by which I can generate one xsd from multiple
> xsd'd.If you can provide me any pointer that will be great help for me.
Previous Topic:Resolving schema import "http://www.w3.org/2000/09/xmldsig"
Next Topic:Being introduced to XSDs
Goto Forum:
  


Current Time: Wed Jul 23 04:11:42 EDT 2014

Powered by FUDForum. Page generated in 0.02227 seconds