Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » XML Schema Definition (XSD) » XML and XSD models from string
XML and XSD models from string [message #75146] Mon, 04 August 2008 13:27 Go to next message
Andre Ribeiro is currently offline Andre Ribeiro
Messages: 58
Registered: July 2009
Member
Hi,

I have my XML and XSDs in DB columns (as strings/text fields).
What is the fastest and best way (regarding memory and performance) to
load the files to ecore models without storing them in a file?

thanks a lot,
André
Re: XML and XSD models from string [message #75163 is a reply to message #75146] Mon, 04 August 2008 14:42 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26014
Registered: July 2009
Senior Member
André,

XMLResource and XSDResourceImpl both support load from a SAX
InputSource. A more generic way is to create a resource and x and call
x.load(new URIConverter.ReadableInputStream(<xmlStringOrReader>, null).
The underlying implementations of XSDResourceImpl and XMLResourceImpl
will unwrap the InputStream and access the string or reader directly,
thereby avoiding the String -> bytes -> String cost.


André Ribeiro wrote:
> Hi,
>
> I have my XML and XSDs in DB columns (as strings/text fields).
> What is the fastest and best way (regarding memory and performance) to
> load the files to ecore models without storing them in a file?
>
> thanks a lot,
> André
Re: XML and XSD models from string [message #75251 is a reply to message #75163] Tue, 05 August 2008 10:20 Go to previous messageGo to next message
Andre Ribeiro is currently offline Andre Ribeiro
Messages: 58
Registered: July 2009
Member
Thanks Ed!

im using the following lines now:
XMLResource x = new XMLResourceImpl();
x.load(new URIConverter.ReadableInputStream(cf.getFileContent()), null);

i just dont get how can i then have (/create) an object (Eobject ?)
that keeps my XML contents and has the model that it validates against?!

To create the model i am trying to use the XSDEcoreBuilder like
XSDEcoreBuilder xsdEcoreBuilder = new XSDEcoreBuilder();
XSDSchema schema = XSDFactory.eINSTANCE.createXSDSchema();
xsdEcoreBuilder.generate(schema);

but since there isnt much (java)docs for these parts i dont know exactly
what this is supposed to do.

My objective is to have an object Model (as the class in OOP) built from
an XSD and the object (as the object in OOP) that is the XML file.
Then i should be able to validate my object against my model.

Is this possible?

Cheers,
André



Ed Merks wrote:
> André,
>
> XMLResource and XSDResourceImpl both support load from a SAX
> InputSource. A more generic way is to create a resource and x and
> call x.load(new URIConverter.ReadableInputStream(<xmlStringOrReader>,
> null). The underlying implementations of XSDResourceImpl and
> XMLResourceImpl will unwrap the InputStream and access the string or
> reader directly, thereby avoiding the String -> bytes -> String cost.
>
>
> André Ribeiro wrote:
>> Hi,
>>
>> I have my XML and XSDs in DB columns (as strings/text fields).
>> What is the fastest and best way (regarding memory and performance)
>> to load the files to ecore models without storing them in a file?
>>
>> thanks a lot,
>> André
Re: XML and XSD models from string [message #75268 is a reply to message #75251] Tue, 05 August 2008 12:17 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26014
Registered: July 2009
Senior Member
André,

Comments below.

André Ribeiro wrote:
> Thanks Ed!
>
> im using the following lines now:
> XMLResource x = new XMLResourceImpl();
> x.load(new URIConverter.ReadableInputStream(cf.getFileContent()),
> null);
>
> i just dont get how can i then have (/create) an object (Eobject ?)
> that keeps my XML contents and has the model that it validates against?!
>
> To create the model i am trying to use the XSDEcoreBuilder like
> XSDEcoreBuilder xsdEcoreBuilder = new XSDEcoreBuilder();
> XSDSchema schema = XSDFactory.eINSTANCE.createXSDSchema();
> xsdEcoreBuilder.generate(schema);
>
> but since there isnt much (java)docs for these parts i dont know
> exactly what this is supposed to do.
I would suggest starting with the library tutorial and generating the
model for the schema you have. Also invoke Generate Test Code and look
at the generated XyzExample.java. This will give you a better starting
point that what you have now. For example, you'll see that it's
important generally to use a resource set and to register a resource
factory.
>
> My objective is to have an object Model (as the class in OOP) built
> from an XSD and the object (as the object in OOP) that is the XML file.
> Then i should be able to validate my object against my model.
>
> Is this possible?
Yes, but you're doing everything the hardest way possible. I'd suggest
reading
http://www.theserverside.com/tt/articles/article.tss?l=Bindi ngXMLJava
and following
http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.emf.doc/tutorials/xlibmod/xlibmod.html
for your schema.
>
> Cheers,
> André
>
>
>
> Ed Merks wrote:
>> André,
>>
>> XMLResource and XSDResourceImpl both support load from a SAX
>> InputSource. A more generic way is to create a resource and x and
>> call x.load(new URIConverter.ReadableInputStream(<xmlStringOrReader>,
>> null). The underlying implementations of XSDResourceImpl and
>> XMLResourceImpl will unwrap the InputStream and access the string or
>> reader directly, thereby avoiding the String -> bytes -> String cost.
>>
>>
>> André Ribeiro wrote:
>>> Hi,
>>>
>>> I have my XML and XSDs in DB columns (as strings/text fields).
>>> What is the fastest and best way (regarding memory and performance)
>>> to load the files to ecore models without storing them in a file?
>>>
>>> thanks a lot,
>>> André
Re: XML and XSD models from string [message #75286 is a reply to message #75268] Tue, 05 August 2008 14:03 Go to previous message
Andre Ribeiro is currently offline Andre Ribeiro
Messages: 58
Registered: July 2009
Member
much thanks for the leads.
will read them carefully.

cheers,
André

Ed Merks wrote:
> André,
>
> Comments below.
>
> André Ribeiro wrote:
>> Thanks Ed!
>>
>> im using the following lines now:
>> XMLResource x = new XMLResourceImpl();
>> x.load(new URIConverter.ReadableInputStream(cf.getFileContent()),
>> null);
>>
>> i just dont get how can i then have (/create) an object (Eobject ?)
>> that keeps my XML contents and has the model that it validates against?!
>>
>> To create the model i am trying to use the XSDEcoreBuilder like
>> XSDEcoreBuilder xsdEcoreBuilder = new XSDEcoreBuilder();
>> XSDSchema schema = XSDFactory.eINSTANCE.createXSDSchema();
>> xsdEcoreBuilder.generate(schema);
>>
>> but since there isnt much (java)docs for these parts i dont know
>> exactly what this is supposed to do.
> I would suggest starting with the library tutorial and generating the
> model for the schema you have. Also invoke Generate Test Code and look
> at the generated XyzExample.java. This will give you a better
> starting point that what you have now. For example, you'll see that
> it's important generally to use a resource set and to register a
> resource factory.
>>
>> My objective is to have an object Model (as the class in OOP) built
>> from an XSD and the object (as the object in OOP) that is the XML file.
>> Then i should be able to validate my object against my model.
>>
>> Is this possible?
> Yes, but you're doing everything the hardest way possible. I'd
> suggest reading
> http://www.theserverside.com/tt/articles/article.tss?l=Bindi ngXMLJava
> and following
> http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.emf.doc/tutorials/xlibmod/xlibmod.html
> for your schema.
>>
>> Cheers,
>> André
>>
>>
>>
>> Ed Merks wrote:
>>> André,
>>>
>>> XMLResource and XSDResourceImpl both support load from a SAX
>>> InputSource. A more generic way is to create a resource and x and
>>> call x.load(new
>>> URIConverter.ReadableInputStream(<xmlStringOrReader>, null). The
>>> underlying implementations of XSDResourceImpl and XMLResourceImpl
>>> will unwrap the InputStream and access the string or reader
>>> directly, thereby avoiding the String -> bytes -> String cost.
>>>
>>>
>>> André Ribeiro wrote:
>>>> Hi,
>>>>
>>>> I have my XML and XSDs in DB columns (as strings/text fields).
>>>> What is the fastest and best way (regarding memory and performance)
>>>> to load the files to ecore models without storing them in a file?
>>>>
>>>> thanks a lot,
>>>> André
Re: XML and XSD models from string [message #603193 is a reply to message #75146] Mon, 04 August 2008 14:42 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26014
Registered: July 2009
Senior Member
André,

XMLResource and XSDResourceImpl both support load from a SAX
InputSource. A more generic way is to create a resource and x and call
x.load(new URIConverter.ReadableInputStream(<xmlStringOrReader>, null).
The underlying implementations of XSDResourceImpl and XMLResourceImpl
will unwrap the InputStream and access the string or reader directly,
thereby avoiding the String -> bytes -> String cost.


André Ribeiro wrote:
> Hi,
>
> I have my XML and XSDs in DB columns (as strings/text fields).
> What is the fastest and best way (regarding memory and performance) to
> load the files to ecore models without storing them in a file?
>
> thanks a lot,
> André
Re: XML and XSD models from string [message #603214 is a reply to message #75163] Tue, 05 August 2008 10:20 Go to previous message
Andre Ribeiro is currently offline Andre Ribeiro
Messages: 58
Registered: July 2009
Member
Thanks Ed!

im using the following lines now:
XMLResource x = new XMLResourceImpl();
x.load(new URIConverter.ReadableInputStream(cf.getFileContent()), null);

i just dont get how can i then have (/create) an object (Eobject ?)
that keeps my XML contents and has the model that it validates against?!

To create the model i am trying to use the XSDEcoreBuilder like
XSDEcoreBuilder xsdEcoreBuilder = new XSDEcoreBuilder();
XSDSchema schema = XSDFactory.eINSTANCE.createXSDSchema();
xsdEcoreBuilder.generate(schema);

but since there isnt much (java)docs for these parts i dont know exactly
what this is supposed to do.

My objective is to have an object Model (as the class in OOP) built from
an XSD and the object (as the object in OOP) that is the XML file.
Then i should be able to validate my object against my model.

Is this possible?

Cheers,
André



Ed Merks wrote:
> André,
>
> XMLResource and XSDResourceImpl both support load from a SAX
> InputSource. A more generic way is to create a resource and x and
> call x.load(new URIConverter.ReadableInputStream(<xmlStringOrReader>,
> null). The underlying implementations of XSDResourceImpl and
> XMLResourceImpl will unwrap the InputStream and access the string or
> reader directly, thereby avoiding the String -> bytes -> String cost.
>
>
> André Ribeiro wrote:
>> Hi,
>>
>> I have my XML and XSDs in DB columns (as strings/text fields).
>> What is the fastest and best way (regarding memory and performance)
>> to load the files to ecore models without storing them in a file?
>>
>> thanks a lot,
>> André
Re: XML and XSD models from string [message #603219 is a reply to message #75251] Tue, 05 August 2008 12:17 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26014
Registered: July 2009
Senior Member
André,

Comments below.

André Ribeiro wrote:
> Thanks Ed!
>
> im using the following lines now:
> XMLResource x = new XMLResourceImpl();
> x.load(new URIConverter.ReadableInputStream(cf.getFileContent()),
> null);
>
> i just dont get how can i then have (/create) an object (Eobject ?)
> that keeps my XML contents and has the model that it validates against?!
>
> To create the model i am trying to use the XSDEcoreBuilder like
> XSDEcoreBuilder xsdEcoreBuilder = new XSDEcoreBuilder();
> XSDSchema schema = XSDFactory.eINSTANCE.createXSDSchema();
> xsdEcoreBuilder.generate(schema);
>
> but since there isnt much (java)docs for these parts i dont know
> exactly what this is supposed to do.
I would suggest starting with the library tutorial and generating the
model for the schema you have. Also invoke Generate Test Code and look
at the generated XyzExample.java. This will give you a better starting
point that what you have now. For example, you'll see that it's
important generally to use a resource set and to register a resource
factory.
>
> My objective is to have an object Model (as the class in OOP) built
> from an XSD and the object (as the object in OOP) that is the XML file.
> Then i should be able to validate my object against my model.
>
> Is this possible?
Yes, but you're doing everything the hardest way possible. I'd suggest
reading
http://www.theserverside.com/tt/articles/article.tss?l=Bindi ngXMLJava
and following
http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.emf.doc/tutorials/xlibmod/xlibmod.html
for your schema.
>
> Cheers,
> André
>
>
>
> Ed Merks wrote:
>> André,
>>
>> XMLResource and XSDResourceImpl both support load from a SAX
>> InputSource. A more generic way is to create a resource and x and
>> call x.load(new URIConverter.ReadableInputStream(<xmlStringOrReader>,
>> null). The underlying implementations of XSDResourceImpl and
>> XMLResourceImpl will unwrap the InputStream and access the string or
>> reader directly, thereby avoiding the String -> bytes -> String cost.
>>
>>
>> André Ribeiro wrote:
>>> Hi,
>>>
>>> I have my XML and XSDs in DB columns (as strings/text fields).
>>> What is the fastest and best way (regarding memory and performance)
>>> to load the files to ecore models without storing them in a file?
>>>
>>> thanks a lot,
>>> André
Re: XML and XSD models from string [message #603224 is a reply to message #75268] Tue, 05 August 2008 14:03 Go to previous message
Andre Ribeiro is currently offline Andre Ribeiro
Messages: 58
Registered: July 2009
Member
much thanks for the leads.
will read them carefully.

cheers,
André

Ed Merks wrote:
> André,
>
> Comments below.
>
> André Ribeiro wrote:
>> Thanks Ed!
>>
>> im using the following lines now:
>> XMLResource x = new XMLResourceImpl();
>> x.load(new URIConverter.ReadableInputStream(cf.getFileContent()),
>> null);
>>
>> i just dont get how can i then have (/create) an object (Eobject ?)
>> that keeps my XML contents and has the model that it validates against?!
>>
>> To create the model i am trying to use the XSDEcoreBuilder like
>> XSDEcoreBuilder xsdEcoreBuilder = new XSDEcoreBuilder();
>> XSDSchema schema = XSDFactory.eINSTANCE.createXSDSchema();
>> xsdEcoreBuilder.generate(schema);
>>
>> but since there isnt much (java)docs for these parts i dont know
>> exactly what this is supposed to do.
> I would suggest starting with the library tutorial and generating the
> model for the schema you have. Also invoke Generate Test Code and look
> at the generated XyzExample.java. This will give you a better
> starting point that what you have now. For example, you'll see that
> it's important generally to use a resource set and to register a
> resource factory.
>>
>> My objective is to have an object Model (as the class in OOP) built
>> from an XSD and the object (as the object in OOP) that is the XML file.
>> Then i should be able to validate my object against my model.
>>
>> Is this possible?
> Yes, but you're doing everything the hardest way possible. I'd
> suggest reading
> http://www.theserverside.com/tt/articles/article.tss?l=Bindi ngXMLJava
> and following
> http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.emf.doc/tutorials/xlibmod/xlibmod.html
> for your schema.
>>
>> Cheers,
>> André
>>
>>
>>
>> Ed Merks wrote:
>>> André,
>>>
>>> XMLResource and XSDResourceImpl both support load from a SAX
>>> InputSource. A more generic way is to create a resource and x and
>>> call x.load(new
>>> URIConverter.ReadableInputStream(<xmlStringOrReader>, null). The
>>> underlying implementations of XSDResourceImpl and XMLResourceImpl
>>> will unwrap the InputStream and access the string or reader
>>> directly, thereby avoiding the String -> bytes -> String cost.
>>>
>>>
>>> André Ribeiro wrote:
>>>> Hi,
>>>>
>>>> I have my XML and XSDs in DB columns (as strings/text fields).
>>>> What is the fastest and best way (regarding memory and performance)
>>>> to load the files to ecore models without storing them in a file?
>>>>
>>>> thanks a lot,
>>>> André
Previous Topic:Dynamic Instance of XSD.ecore
Next Topic:Format of serialized XML
Goto Forum:
  


Current Time: Sat Aug 30 20:38:25 EDT 2014

Powered by FUDForum. Page generated in 0.01829 seconds