validation of XML versus XSD

VA Smalltalk is a "100% VisualAge compatible" IDE that includes the original VisualAge technology and the popular VA Assist and WidgetKit add-ons.

Moderators: Eric Clayberg, wembley, tc, Diane Engles, solveig

validation of XML versus XSD

Postby benvandijk » Fri Jul 18, 2008 1:49 am

Hi Guys,

I receive xml from a third party webservice which is validated by Vast against an xsd supplied by the same third party.
Sometimes the xml is rejected by vast because it fails the validation. I get the message
Content '''' does not conform to facet (length = 12)

This message is generated by the method validate: in AbtXmlSchemaRestriction.

The xsd states a length of 12 for the element, but the element contains an empty string.
That explains the generated exception, but the xsd also states that the element can be nil.

My question is: Should Vast in this case handle an empty string the same as nil or is the xsd incorrect?

The snippet of xml as parsed by AbtXmlMappingParser:
Code: Select all
<audp:vgs-codes><audp:vgs-code xsi:nil="true"/></audp:vgs-codes>


The snippet of xsd :
Code: Select all
   <xsd:complexType name="uitvoeringsinfo">
      <xsd:sequence>
         <xsd:element name="vgs-codes" type="vgs-codes" nillable="true"/>
      </xsd:sequence>
   </xsd:complexType>
   <xsd:complexType name="vgs-codes">
      <xsd:sequence>
         <xsd:element name="vgs-code" type="vgs-code" maxOccurs="unbounded"/>
      </xsd:sequence>
   </xsd:complexType>
   <xsd:simpleType name="vgs-code">
      <xsd:restriction base="xsd:string">
         <xsd:length value="12"/>
      </xsd:restriction>
   </xsd:simpleType>


Greetz, Ben
benvandijk
 
Posts: 45
Joined: Sun Feb 25, 2007 7:14 am
Location: Arnhem, Netherlands

Re: validation of XML versus XSD

Postby rjs » Fri Jul 18, 2008 9:48 am

Hi Ben,

I am not an XML expert by any stretch. However, I read the XSD with no possibility of the vgscode being other than 12 bytes. It's type declaration does not provide for it being nil.

I read the XSD as defining a container for a collection of 0 or more codes, each code of which must be 12 bytes.

The XML attempts to define a collection with one element which is nil. That does not meet the requirements defined by the XSD.



Richard
rjs
 
Posts: 39
Joined: Thu Mar 27, 2008 11:07 am
Location: Port Perry, Ontario, Canada

Re: validation of XML versus XSD

Postby benvandijk » Mon Jul 21, 2008 11:22 pm

Hi Richard,

When i look at the xsd i come to the same conclusion. the vgs-code must have a length of 12 when filled.
However, the xml processed in the AbtXmlParser states xsi:nil="true" for the vgs_code.
The parser translates the contents of vgs-code to an empty String, not a nil object.

When i change the contents to nil, this is accepted by the validation routines.

Now i am confused on two points
1. The xsd states vgs-code is a string of 12 which can not be nil, but the validating parser accepts nil.
2. The vgs-code in the xml is empty, but the parser translates the content to an empty string. why?

greetings, Ben.
benvandijk
 
Posts: 45
Joined: Sun Feb 25, 2007 7:14 am
Location: Arnhem, Netherlands

Re: validation of XML versus XSD

Postby rjs » Tue Jul 22, 2008 8:24 am

benvandijk wrote:... the xml processed in the AbtXmlParser states xsi:nil="true" for the vgs_code.
The parser translates the contents of vgs-code to an empty String, not a nil object.

When i change the contents to nil, this is accepted by the validation routines.

Now i am confused on two points
1. The xsd states vgs-code is a string of 12 which can not be nil, but the validating parser accepts nil.
2. The vgs-code in the xml is empty, but the parser translates the content to an empty string. why?


First, I don't understand what you mean when you write "When i change the contents to nil". Perhaps this is after the validator has checked things?


<audp:vgs-code xsi:nil="true"/> should have parsed as a nil, not a String. I don't know the parser well enough to explain why.

This variant: <audp:vgs-code /> shoud be parsed as an empty String, but even then the validator should have rejected it for not being 12 bytes long. [IMO]


At this point, I think you need answers from some one who knows the parser and validator (some one from Instantiations, most likely).
rjs
 
Posts: 39
Joined: Thu Mar 27, 2008 11:07 am
Location: Port Perry, Ontario, Canada

Re: validation of XML versus XSD

Postby Diane Engles » Mon Jul 28, 2008 6:58 am

After looking at the schema and the xml, it seems to me that the element which is nillable is vgs-codes, not vgs-code. What happens if the xsi:nil="true" atttribute is declared in the vgs-codes element?
Instantiations Smalltalk Support
diane@instantiations.com
Diane Engles
Moderator
 
Posts: 66
Joined: Mon Oct 16, 2006 2:40 pm

Re: validation of XML versus XSD

Postby benvandijk » Wed Jul 30, 2008 6:58 am

Richard and Diane,

Thanks for helping me on the right track.
I took a deeper look at the parser and found the cause of the problem.
During deserialization the parser follows the xsd, setting the value of element vgs-code to an empty string.
(vgs-code is a string and can not be nullable according to the xsd.)
The validator checks the value of vgs-code to its restriction (String, length 12) and rejects the value.

This implies that the xsi:nil="true" attribute on the xml is completely ignored.
Ok, I can understand the logic of this.

I changed the xsd, adding a nillable="true" attribute to vgs-code and everything runs perfectly.

Greetings, Ben.
benvandijk
 
Posts: 45
Joined: Sun Feb 25, 2007 7:14 am
Location: Arnhem, Netherlands


Return to VA Smalltalk 7.0, 7.5 & 8.0

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest