Home » Archived » XML Schema Definition (XSD) » XML and XSD models from string
| | |
Re: XML and XSD models from string [message #75268 is a reply to message #75251] |
Tue, 05 August 2008 16:17 |
Ed Merks Messages: 33218 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é
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: XML and XSD models from string [message #75286 is a reply to message #75268] |
Tue, 05 August 2008 18:03 |
Andre Ribeiro Messages: 52 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 18:42 |
Ed Merks Messages: 33218 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é
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| |
Re: XML and XSD models from string [message #603219 is a reply to message #75251] |
Tue, 05 August 2008 16:17 |
Ed Merks Messages: 33218 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é
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: XML and XSD models from string [message #603224 is a reply to message #75268] |
Tue, 05 August 2008 18:03 |
Andre Ribeiro Messages: 52 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é
|
|
|
Goto Forum:
Current Time: Thu Sep 26 14:42:11 GMT 2024
Powered by FUDForum. Page generated in 0.05516 seconds
|