From: Ben C. <ben...@gm...> - 2009-09-08 12:41:42
|
Howdy, I am a newbie to XML but have been using TCL a few years. Today I have read through every bit of documentation I can find but I am still not clear how to do XSD-style validation or if it is possible with TclXML. I basically need to read in a file, validate it and parse it - no manipulation so DOM would be overkill. The parsing is clear from the manual, but it's not clear what results from use of the -validation switch and if XSD schema are supported. Running my parser with libxml2 and -validate true returns ok but this doesn't convince me the xsd has been found, parsed and used to validate the document. Can anyone help? BC |
From: Steve B. <Ste...@ex...> - 2009-09-09 21:10:27
|
Hi Ben, TclXML/libxml2 v3.2 supports XSD schema validation and the upcoming v3.3 will support RelaxNG schema validation. Schema validation is usually performed post-parsing, upon the document DOM tree; I'll need to check whether validation works as expected during parsing. Anyway, sometime today I'll see if I can post an example on the Tcl Wiki. For another example see the tkxmllint application. Also, if you want to confirm that the XSD parsing is working then the easiest way to do that would be to feed a known schema-invalid document into the system and check that it correctly reports an error. You can also feed it a deliberately incorrect schema document and check that it fails at the compilation stage. Cheers, Steve Ball On 08/09/2009, at 10:41 PM, Ben Carbery wrote: > Howdy, > > I am a newbie to XML but have been using TCL a few years. Today I > have read through every bit of documentation I can find but I am > still not clear how to do XSD-style validation or if it is possible > with TclXML. > > I basically need to read in a file, validate it and parse it - no > manipulation so DOM would be overkill. The parsing is clear from the > manual, but it's not clear what results from use of the -validation > switch and if XSD schema are supported. > > Running my parser with libxml2 and -validate true returns ok but > this doesn't convince me the xsd has been found, parsed and used to > validate the document. > > Can anyone help? > > BC > > > ------------------------------------------------------------------------------ > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 > 30-Day > trial. Simplify your report design, integration and deployment - and > focus on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july_______________________________________________ > Tclxml-users mailing list > Tcl...@li... > https://lists.sourceforge.net/lists/listinfo/tclxml-users |
From: Ben C. <ben...@gm...> - 2009-09-11 00:39:13
|
Hi Steve, Thanks, another user pointed me to the solution which it turns out is documented under the DOM manual. I hope they won't mind if I copy their code below for other readers. I initially verified my XML and XSD using a web service, then confirmed that validation is working correctly as you suggested. I'm still not entirely clear what results from using the validation option with just the tclxml package, as documented here: http://tclxml.sourceforge.net/tclxml/3.2/tclxml.html#id19102. By the way I notice that "cget -parser" raises an error, but "cget * -option: Returns the current value of the configuration option given by option. Option may have any of the values accepted by the parser object."* ##################################### package require xml package require xml::libxml2 package require dom # Reads the document to validate set text [read [open /xmlfiles/atmoa4_atmos_smioc.xml ]] set doc [dom::parse $text] # Reads the validating schema set schema_text [read [open /xmlfiles/smioc.xsd ]] set schema_doc [dom::parse $schema_text] # Compile the schema $schema_doc schema compile # Do the actual validation $schema_doc schema validate $doc On Thu, Sep 10, 2009 at 7:10 AM, Steve Ball <Ste...@ex...>wrote: > Hi Ben, > > TclXML/libxml2 v3.2 supports XSD schema validation and the upcoming v3.3 > will support RelaxNG schema validation. Schema validation is usually > performed post-parsing, upon the document DOM tree; I'll need to check > whether validation works as expected during parsing. > > Anyway, sometime today I'll see if I can post an example on the Tcl Wiki. > For another example see the tkxmllint application. > > Also, if you want to confirm that the XSD parsing is working then the > easiest way to do that would be to feed a known schema-invalid document into > the system and check that it correctly reports an error. You can also feed > it a deliberately incorrect schema document and check that it fails at the > compilation stage. > > Cheers, > Steve Ball > > |