Hello
I'm just getting my feet wet with XML and I'm kind of stuck. What I'd like to do is add XML support to my app (XML will just serve as "model interchange format"). There is basically one schema file (at http://www.optimizationservices.org/schemas/OSiL.xsd) I need (it imports some others) and I have some examples XML files (locally). What I'd like to do: parse the schema, parse the example and validate the example (w.r.t. the schema). I read the "WebServices.pdf" but I'm a bit lost... I started with something like: xmlToObjElement := XMLTypesParser url: 'http://www.optimizationservices.org/schemas/OSiL.xsd'. binding := (XMLObjectBinding buildBindings: (Array with: xmlToObjElement)) first. manager := XMLObjectMarshalingManager on: binding. However, as soon as the base schema imports other schemas, I get the following error: "unhandled exception" with "This URI does not contain a protocol." I traced it down to the XML snippet <xs:include schemaLocation="OSgL.xsd"/> in the above mentioned schema file "http://www.optimizationservices.org/schemas/OSiL.xsd" Is this a VW bug? An error in the XML schema? Is there a known workaround? Or, what am I doing wrong? Thanks a lot Mike |
For basic XML support, see BasicLibraries.pdf, the chapter on XML. There should be (well, in theory at least) enough information there to get you started.
Bruce ----- Original Message ----- From: "Mike Bielser" <[hidden email]> To: <[hidden email]> Sent: Thursday, June 14, 2007 6:42 AM Subject: XML and VW7.5 NC | Hello | I'm just getting my feet wet with XML and I'm kind of stuck. What I'd | like to do is add XML support to my app (XML will just serve as "model | interchange format"). There is basically one schema file (at | http://www.optimizationservices.org/schemas/OSiL.xsd) I need (it imports | some others) and I have some examples XML files (locally). What I'd | like to do: parse the schema, parse the example and validate the example | (w.r.t. the schema). | I read the "WebServices.pdf" but I'm a bit lost... I started with | something like: | | xmlToObjElement := XMLTypesParser url: | 'http://www.optimizationservices.org/schemas/OSiL.xsd'. | binding := (XMLObjectBinding buildBindings: (Array with: | xmlToObjElement)) first. | manager := XMLObjectMarshalingManager on: binding. | | However, as soon as the base schema imports other schemas, I get the | following error: | | "unhandled exception" with "This URI does not contain a protocol." | | I traced it down to the XML snippet <xs:include | schemaLocation="OSgL.xsd"/> in the above mentioned schema file | "http://www.optimizationservices.org/schemas/OSiL.xsd" | | Is this a VW bug? An error in the XML schema? Is there a known | workaround? Or, what am I doing wrong? | | Thanks a lot | Mike | |
If you need to use XML to object binding you can try the following code
to create a binding and unmarshal an XML file: (x20 := XMLTypesParser defaultBinding) baseURI:'http://www.optimizationservices.org/schemas/OSiL.xsd' asURI; readFrom:'http://www.optimizationservices.org/schemas/OSiL.xsd' asURI. b := XMLObjectBinding loadFrom: x20 printString readStream. manager := XMLObjectMarshalingManager on: b. xml := (XMLParser on: aDataSource) validate: false; scanDocument. doc := manager unmarshal: xml atNamespace: 'os.optimizationservices.org'. The connection was not responding when the http client tried to read the schema from the <include> statement. Tamara Kogan Smalltalk development, Cincom Systems > -----Original Message----- > From: Bruce Boyer [mailto:[hidden email]] > Sent: Thursday, June 14, 2007 9:54 AM > To: Mike Bielser; [hidden email] > Subject: Re: XML and VW7.5 NC > > For basic XML support, see BasicLibraries.pdf, the chapter on XML. There > should be (well, in theory at least) enough information there to get you > started. > > Bruce > > ----- Original Message ----- > From: "Mike Bielser" <[hidden email]> > To: <[hidden email]> > Sent: Thursday, June 14, 2007 6:42 AM > Subject: XML and VW7.5 NC > > > | Hello > | I'm just getting my feet wet with XML and I'm kind of stuck. What > | like to do is add XML support to my app (XML will just serve as "model > | interchange format"). There is basically one schema file (at > | http://www.optimizationservices.org/schemas/OSiL.xsd) I need (it imports > | some others) and I have some examples XML files (locally). What I'd > | like to do: parse the schema, parse the example and validate the example > | (w.r.t. the schema). > | I read the "WebServices.pdf" but I'm a bit lost... I started with > | something like: > | > | xmlToObjElement := XMLTypesParser url: > | 'http://www.optimizationservices.org/schemas/OSiL.xsd'. > | binding := (XMLObjectBinding buildBindings: (Array with: > | xmlToObjElement)) first. > | manager := XMLObjectMarshalingManager on: binding. > | > | However, as soon as the base schema imports other schemas, I get the > | following error: > | > | "unhandled exception" with "This URI does not contain a protocol." > | > | I traced it down to the XML snippet <xs:include > | schemaLocation="OSgL.xsd"/> in the above mentioned schema file > | "http://www.optimizationservices.org/schemas/OSiL.xsd" > | > | Is this a VW bug? An error in the XML schema? Is there a known > | workaround? Or, what am I doing wrong? > | > | Thanks a lot > | Mike > | |
Hi Tamara
thank you very much for your help. I started with the code snippet you provided; this snippet was somewhat similar to mine. However, executing your code in a workspace would bring up the hourglass cursor, then the trash can cursor, then the GC cursor. This "cursor sequence" repeated over and over, usually until I lost patience (at which point VW had consumed about 180 MB of RAM and I had to kill the workspace using the ProcessViewer). It quickly turned out that there were cyclic imports/includes of schema files; at least in my case the involved VW XML classes do not seem to like this! I downloaded all the schema files, deleted any cyclic includes and got started. The next offending line of code seems to be binding := XMLObjectBinding loadFrom: x20 printString readStream which is not valid XML code but just a ByteString containing 'a WebServices.XMLTypesParser'. So I replaced it with this code of mine: tmpStream := (String new: 5000) readWriteStream. x20 schemaBindings printCanonicalOn: tmpStream. tmpStream reset. binding := XMLObjectBinding loadBindings: tmpStream. In the last line of code above, at some point VW yells at me saying: Unhandled exception: Message not understood: #relations WebServices.ChoiceMarshaler(Object)>>doesNotUnderstand: WebServices.GroupMarshaler>>setAttributesFrom:in: WebServices.GroupMarshaler(WebServices.XMLTypeMarshaler)>>setAttributesFrom:in:name: WebServices.BindingBuilder>>startBinding:attributes: WebServices.BindingBuilder>>startElement:localName:qName:attributes: And now I'm really lost...Can I tell VW to ignore some schema elements (like this one), to get past such errors??? Or what do I do? Thanks a lot for your help so far! Kind regards Mike |
> It quickly turned out that there were cyclic imports/includes of
schema > files; at least in my case the involved VW XML classes do not seem to > like this! It is a bug. We should take care of cyclic references. Is these any way to send some test case? > In the last line of code above, at some point VW yells at me saying: > > Unhandled exception: Message not understood: #relations > WebServices.ChoiceMarshaler(Object)>>doesNotUnderstand: > WebServices.GroupMarshaler>>setAttributesFrom:in: > WebServices.GroupMarshaler(WebServices.XMLTypeMarshaler)>>setAttributesF ro > m:in:name: > WebServices.BindingBuilder>>startBinding:attributes: > WebServices.BindingBuilder>>startElement:localName:qName:attributes: > > And now I'm really lost...Can I tell VW to ignore some schema elements > (like this one), to get past such errors??? Or what do I do? It looks like we don't handle a choice inside a group element properly. There is no way to ignore this element while loading the binding. You can try to modify the xml to object binding and reload the binding. If your xml looks like: <struct name="myGroup"> <choice> <element ref="xsd:int" name="int"/> <element name="group2" ref="xsd:string"/> </choice> </struct> <struct name="Item" tag="Item"> <group name="myGroup" ref="tns:myGroup"/> <element ref="tns:Item" /> </struct> You can remove the <choice> element and the group elements will be treated as <sequence>: <struct name="myGroup"> <element ref="xsd:int" name="int"/> <element name="group2" ref="xsd:string"/> </struct> Tamara |
In reply to this post by Mike Bielser
> Unhandled exception: Message not understood: #relations > WebServices.ChoiceMarshaler(Object)>>doesNotUnderstand: > WebServices.GroupMarshaler>>setAttributesFrom:in: > WebServices.GroupMarshaler(WebServices.XMLTypeMarshaler)>>setAttributesF ro > m:in:name: > WebServices.BindingBuilder>>startBinding:attributes: > WebServices.BindingBuilder>>startElement:localName:qName:attributes: Could you, please, send me the group element? I was able to load a group with choice element in 75: bindingSpec := XMLTypesParser readFrom: '<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://testGroupChoice" targetNamespace="http://testGroupChoice"> <xsd:element name="Item"> <xsd:complexType> <xsd:sequence> <xsd:group ref="myGroup"/> <xsd:element name="aaa" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:group name="myGroup"> <xsd:choice> <xsd:element name="string" type="xsd:string"/> <xsd:element name="int" type="xsd:int"/> </xsd:choice> </xsd:group> </xsd:schema>'. b := XMLObjectBinding loadFrom: bindingSpec printString readStream. Tamara |
Kogan, Tamara wrote:
<snip> > Could you, please, send me the group element? I was able to load a group > with choice element in 75: <snip> Here you go: <xs:group name="DistributionGroup"> <xs:choice> <xs:group ref="DiscreteDistributionGroup"/> <xs:group ref="ContinuousDistributionGroup"/> </xs:choice> </xs:group> <xs:group name="DiscreteDistributionGroup"> <xs:choice> <xs:element ref="empiricalDiscrete"/> <xs:element ref="discreteUniform"/> <xs:element ref="bernoulli"/> <xs:element ref="binomial"/> <xs:element ref="hypergeometric"/> <xs:element ref="poisson"/> <xs:element ref="geometric"/> <xs:element ref="negativeBinomial"/> </xs:choice> </xs:group> The above snippet is the first occurence of element "group" in the schema "OSgL.xsd", which actually gets imported/included by the schema "OSiL.xsd" (the start/mother schema). I have attached the EDITED schemas (i.e. the ones where I manually deleted any cyclic includes). I started editing the VW code this afternoon (well, afternoon here in Switzerland) to handle this "group" thing, but I don't know whether I'll be able to fix it... Kind regards Mike schemas.zip (22K) Download Attachment |
In reply to this post by Kogan, Tamara
I copied your code:
> I was able to load a group with choice element in 75: > > bindingSpec := XMLTypesParser readFrom: > '<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" > xmlns="http://testGroupChoice" > targetNamespace="http://testGroupChoice"> > <xsd:element name="Item"> > <xsd:complexType> > <xsd:sequence> > <xsd:group ref="myGroup"/> > <xsd:element name="aaa" type="xsd:string"/> > </xsd:sequence> > </xsd:complexType> > </xsd:element> > > <xsd:group name="myGroup"> > <xsd:choice> > <xsd:element name="string" type="xsd:string"/> > <xsd:element name="int" type="xsd:int"/> > </xsd:choice> > </xsd:group> > > </xsd:schema>'. > b := XMLObjectBinding loadFrom: bindingSpec printString readStream. > into a workspace and got the following error: Unhandled exception: Illegal volume specification FATFilename class(PCFilename class)>>readVolumeFrom: FATFilename class(PCFilename class)>>readBaseLocationFromStream: FATFilename class(Filename class)>>components: The stream (that readVolumeFrom: expects) starts with "<xsd:" Do you have anything special loaded from the Cincom Public Repository? I opened the Parcel Manager (tab "Suggestions", folder "Web Services" on the left), other than "Opentalk-CGI" I have every parcel loaded into a clean VW7.5NC image (on WinXP SP2). Really puzzling... Mike |
I changed the workspace code to
bindingSpec := XMLTypesParser readFrom: '<xsd:schema ... snip ... </xsd:schema>' readStream. b := XMLObjectBinding loadFrom: bindingSpec printString readStream. and now it works. So the missing "readStream" was the culprit in your small example. Unfortunately, this still does not solve the group/choice problem in my schemas... Mike |
This workspace code works (but please note I had to change all "ref" to
"name" within the choice element in order to avoid an "unresolved reference signal"): bindingSpec := XMLTypesParser readFrom: '<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://testGroupChoice" targetNamespace="http://testGroupChoice"> <xs:group name="DiscreteDistributionGroup"> <xs:choice> <xs:element name="empiricalDiscrete"/> <xs:element name="discreteUniform"/> <xs:element name="bernoulli"/> <xs:element name="binomial"/> <xs:element name="hypergeometric"/> <xs:element name="poisson"/> <xs:element name="geometric"/> <xs:element name="negativeBinomial"/> </xs:choice> </xs:group> </xs:schema>' readStream. b := XMLObjectBinding loadFrom: bindingSpec printString readStream. Mike |
This workspace code does NOT work (at least not in my setup := clean
image + "Web Services" - "Opentalk-CGI"). bindingSpec := XMLTypesParser readFrom: '<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://testGroupChoice" targetNamespace="http://testGroupChoice"> <xs:group name="DistributionGroup"> <xs:choice> <xs:group ref="DiscreteDistributionGroup"/> <xs:group ref="ContinuousDistributionGroup"/> </xs:choice> </xs:group> </xs:schema>' readStream. b := XMLObjectBinding loadFrom: bindingSpec printString readStream. Comparing this with the former example reveals that the culprit is "groups within a choice". As long as you have "elements within a choice", things are fine. From my point of view, this is a bug in VW7.5NC Mike |
In reply to this post by Mike Bielser
Hi Mike,
I was able to create x2o binding from the schemas you sent in 75. There was no problem with the include statements. I copied all file in one directory and did: (parser := XMLTypesParser defaultBinding) baseURI: 'F:\vw7\image\bugs\OSgl\OSiL.xsd' asFilename asURI; readFrom:'F:\vw7\image\bugs\OSgl\OSiL.xsd' asFilename asURI. b := XMLObjectBinding buildBindings: parser schemaBindings realElements. With the attached patch the binding was loaded. I created an AR for the case. It took for a while to create the binding. There are more than 900 marshalers in this binding. Tamara Kogan Smalltalk development, Cincom Systems > -----Original Message----- > From: Mike Bielser [mailto:[hidden email]] > Sent: Monday, June 18, 2007 2:35 PM > To: Kogan, Tamara > Cc: Bruce Boyer; [hidden email] > Subject: Re: XML and VW7.5 NC > > Kogan, Tamara wrote: > > > <snip> > > > Could you, please, send me the group element? I was able to load a > > with choice element in 75: > > <snip> > > > Here you go: > > <xs:group name="DistributionGroup"> > <xs:choice> > <xs:group ref="DiscreteDistributionGroup"/> > <xs:group ref="ContinuousDistributionGroup"/> > </xs:choice> > </xs:group> > <xs:group name="DiscreteDistributionGroup"> > <xs:choice> > <xs:element ref="empiricalDiscrete"/> > <xs:element ref="discreteUniform"/> > <xs:element ref="bernoulli"/> > <xs:element ref="binomial"/> > <xs:element ref="hypergeometric"/> > <xs:element ref="poisson"/> > <xs:element ref="geometric"/> > <xs:element ref="negativeBinomial"/> > </xs:choice> > </xs:group> > > The above snippet is the first occurence of element "group" in the > schema "OSgL.xsd", which actually gets imported/included by the schema > "OSiL.xsd" (the start/mother schema). > I have attached the EDITED schemas (i.e. the ones where I manually > deleted any cyclic includes). I started editing the VW code this > afternoon (well, afternoon here in Switzerland) to handle this "group" > thing, but I don't know whether I'll be able to fix it... > > Kind regards > Mike XMLObjectMarshalers.zip (396 bytes) Download Attachment |
Hi Tamara
I tried the attachment, but both on WinXP as well as on MacOS 10.4 the file "XMLObjectMarshalers.st" ( the only one within the ZIP archive) contains (basically) nothing: <?xml version="1.0"?> <st-source> <time-stamp>From VisualWorks®, Pre-Release 7.5.1 (jun07.2) of June 11, 2007 on June 19, 2007 at 8:04:54 am</time-stamp> </st-source> Is this really all there is in this file? Kind regards Mike |
Indeed, that file out is empty.
-Boris -- +1.604.689.0322 DeepCove Labs Ltd. 4th floor 595 Howe Street Vancouver, Canada V6C 2T5 http://tinyurl.com/r7uw4 [hidden email] CONFIDENTIALITY NOTICE This email is intended only for the persons named in the message header. Unless otherwise indicated, it contains information that is private and confidential. If you have received it in error, please notify the sender and delete the entire message including any attachments. Thank you. > -----Original Message----- > From: Mike Bielser [mailto:[hidden email]] > Sent: Tuesday, June 19, 2007 2:24 PM > To: Kogan, Tamara > Cc: Bruce Boyer; [hidden email] > Subject: Re: XML and VW7.5 NC > > Hi Tamara > I tried the attachment, but both on WinXP as well as on MacOS 10.4 the > file "XMLObjectMarshalers.st" ( the only one within the ZIP archive) > contains (basically) nothing: > > <?xml version="1.0"?> > > <st-source> > <time-stamp>From VisualWorks(r), Pre-Release 7.5.1 (jun07.2) of June > 2007 on June 19, 2007 at 8:04:54 am</time-stamp> > > > </st-source> > > Is this really all there is in this file? > > Kind regards > Mike |
In reply to this post by Mike Bielser
Sorry, about it. Try the attached file.
Tamara Kogan Smalltalk development, Cincom Systems > -----Original Message----- > From: Mike Bielser [mailto:[hidden email]] > Sent: Tuesday, June 19, 2007 5:24 PM > To: Kogan, Tamara > Cc: Bruce Boyer; [hidden email] > Subject: Re: XML and VW7.5 NC > > Hi Tamara > I tried the attachment, but both on WinXP as well as on MacOS 10.4 the > file "XMLObjectMarshalers.st" ( the only one within the ZIP archive) > contains (basically) nothing: > > <?xml version="1.0"?> > > <st-source> > <time-stamp>From VisualWorks(r), Pre-Release 7.5.1 (jun07.2) of June > 2007 on June 19, 2007 at 8:04:54 am</time-stamp> > > > </st-source> > > Is this really all there is in this file? > > Kind regards > Mike ChoiceGroupChanges.zip (1K) Download Attachment |
Kogan, Tamara wrote:
> Sorry, about it. Try the attached file. > > Tamara Kogan > Smalltalk development, > Cincom Systems Hi Tamara great, it works, thanks a million! So, to recap (from my point of view): 1) I had to delete any cyclic includes/imports in the schema files manually (not a big deal here, but I think VW should handle this "automagically") 2) Nested "group-choice-group" constructs (and similiar ones) do not work (without your patch). Thanks again Mike |
Free forum by Nabble | Edit this page |