Validating XML with 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

Validating XML with XSD

Postby thunderman74 » Fri Feb 12, 2010 6:31 am

Hi All,

We have a need to validate an incoming XML file against an xml schema file. I can see in the SAX parser how to use a DTD, but we are using XSD and not DTD. Does anyone have any sample code
that utilizes the Schema classes to do this. There is no clear way on how to use that stuff. I wish there was a helper class to just plug in an XML and XSD ;-)

Thanks,

Matthew MacMillan
Fiserv Corporation
thunderman74
 
Posts: 2
Joined: Fri Feb 12, 2010 6:16 am

Re: Validating XML with XSD

Postby tc » Fri Feb 12, 2010 9:11 am

Hello,

Here is what Bryan Hogan wrote sometime back:
VA contains only rudimentary support for validation of XML documents against a schema. The primary goal of the schema support in VAST was to enable support for Web services. The Web services support uses XML schemas to map incoming XML data into corresponding Smalltalk objects. Some validation occurs as part of this mapping, but full schema validation is not supported.

. . . I had a simple example but it does not work but shows the basic idea. The schema file is (address-schema.xsd):
Code: Select all
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="fullName" type="xs:string"/>
</xs:schema>

. . . and the xml file is (addressdoc.xml):
Code: Select all
<?xml version="1.0"?>
<fullName xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:noNamespaceSchemaLocation="address-schema.xsd">Scott</fullName>

. . . the st code is:
Code: Select all
| parser |
parser := AbtXmlDOMParser newValidatingParser.
parser parseURI: 'C:\temp\addressdoc.xml'

. . . however, the parser will throw an exception and a 'AbtXmlDOMParser newNonValidatingParser' will always parse it as being correct.

--tc
tc
Moderator
 
Posts: 304
Joined: Tue Oct 17, 2006 7:40 am
Location: Raleigh, NC

Re: Validating XML with XSD

Postby thunderman74 » Fri Feb 12, 2010 10:00 am

Thanks for the quick response. I was hoping for a different answer. I guess I could convert the XSD to DTD...but would lose some validation integrity.

Thanks again!!
thunderman74
 
Posts: 2
Joined: Fri Feb 12, 2010 6:16 am


Return to VA Smalltalk 7.0, 7.5 & 8.0

Who is online

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