Validating XML against XSD

forum.sourcecode (2000-2005) & forum.td.sourcecode (2005-2010)
Alexander Traxler

Validating XML against XSD

Post by Alexander Traxler » 21 Jun 2007, 14:45

 Posted by:  Alexander Traxler 

Hello Newsgroup!

Has anyone an example on how to validate a XML (already read into a
DOM-Class) against a XSD?
Preferred TD3.1, XML3.0

Can somone tell me how to do this?

Cheers,
Alex

Jeff Luther
Site Admin
Site Admin
United States of America
Posts: 2370
Joined: 04 Mar 2017, 18:34
Location: Palm Springs, California

Re: Validating XML against XSD

Post by Jeff Luther » 21 Jun 2007, 17:50

 Posted by:  Jeff Luther 

Maybe someone will post an example of validating, Alex. But I had not
heard of this, so searched the 'net for XSD and came up with this link:
http://xmlfox.com/validate_xml.htm

It even shows link to a product/utility that will validate for you.

It still begs the question for me: What are the validation rules used
to compare an XML file with an XSD? Do you know that? I'm sure a link
in the search list might provide that, though didn't see it directly.

There are also what seem to be good links with the search: xsd validation
They might help you as well.

Best Regards,
Jeff @ PC Design
info. & samples: www.JeffLuther.net/gupta/

Alexander Traxler

Re: Validating XML against XSD

Post by Alexander Traxler » 22 Jun 2007, 13:54

 Posted by:  Alexander Traxler 

Hello Jeff!

Thanx for your suggestions!
I'll take a look at the link and keep on searching the net, too.

But it would still be great, if someone has an example in Gutpa-Code how to
validate against XSD.

Cheers,
Alex

Alexander Traxler

Re: Validating XML against XSD

Post by Alexander Traxler » 22 Jun 2007, 17:02

 Posted by:  Alexander Traxler 

Let me precise my situation:
I'm about to consume a webservice. My request includes data in XML for this
webservice as it is an order for pharmaceutics.
As response there is again XML to be analysed.
On my local machine there are XSD-files that contain the schemas for a valid
response.
Now I want to validate my XML in the response against these XSD-files, to
know the data is formatted correctly so I don't have to parse on my own
while processing the response.

The response then is already contained in a DOM-structure (as it comes in
the webservice-response).
The XSD is locally stored in a file.

Has someone such an example or can give me hints about that?
Even tips for tools would be appreciated!

Thanx in advance!

Cheers,
Alex

StefanM
Germany
Posts: 679
Joined: 10 Aug 2018, 15:57
Location: Bavaria

Re: Validating XML against XSD

Post by StefanM » 23 Jun 2007, 01:09

 Posted by:  Stefan Misch 

Alexander,

I don't have an example at hand right now. I describe what you have to
do from my memory. I assume you use at least version 4.0 of the MSXML
Parser. I also assume you know how to build the APL with the ActiveX
wizzard.

(1) load the XMLSchema XSD file in a DOM document object
(2) create a schema cache (MSXML2_XMLSchemaCache?) object and add your
schema to the cache
(3) load your XML file into a DOM document
(4) set "validateOnParse"
(5) set the document schemas to the schema cache
(6) load the XML file

You may want to check for any parse errors.

HTH,
Stefan

Alexander Traxler

Re: Validating XML against XSD

Post by Alexander Traxler » 25 Jun 2007, 11:57

 Posted by:  Alexander Traxler 

Hello Stefan,

Thanx for the "walkthrough", this seems to do the validation.

Cheers,
Alex

Alexander Traxler

Re: Validating XML against XSD

Post by Alexander Traxler » 27 Jun 2007, 10:45

 Posted by:  Alexander Traxler 

Hi!

This is now my sample-function on how to do the XML validation.
TD 3.1, using the MSXML4.0 .

Cheers,
Alex

You do not have the required permissions to view the files attached to this post.

Return to “td.sourcecode”

Who is online

Users browsing this forum: [Ccbot] and 0 guests