ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl-xml
perl-xml
Validating with XML::LibXML::RelaxNG?
by Rodent of Unusual Size other posts by this author
Jul 4 2009 4:23PM messages near this date
view in the new Beta List Site
Re: how can I get the attribute names? | Validating with XML::LibXML::RelaxNG?
& XSLT I'm getting seemingly anomalous results when using
XML::LibXML::RelaxNG to validate documents.

Firstly, is an instance supposed to be reusable?  Can
it be used to validate multiple RNG documents in sequence?
Or do I need to instantiate a new object for each document
I want to validate?  Empirical evidence suggests the former,
but it doesn't appear to be clearly spelt out in the docco.

Next: I'm using XML::LibXML::RelaxNG to verify a schema --
sort of working in both directions, as it were.  I build a
document incrementally and validate it at each stage to make
sure that a) I'm not messing up the structure of the document
as I build it, and b) that the RNG schema agrees with me about
what's valid.  Included in the testing are intentional errors
to make sure the schema catches them, too.

If I take this incremental document and export it to XML with
its toString() method, create a new document from it with
XML::LibXML-> new(string => $foo), and pass the result to
$rng-> validate(), it *always* behaves as expected.  If I pass
it the XML::LibXML::Document object I've been frobbing, it
sometimes says the invalid XML is, in fact, valid.

I'm frobbing the document with addChild() and removeChild(), using
element objects I created at the beginning with createElement().
In other words, the same nodes are getting moved around:
inserted here, removed and re-inserted over there, etc.

The document's toString() output shows the correct XML.  Is
what I'm doing with shuffling nodes not supported at some
level?  Are there artifacts of the shuffling that are getting
left behind and confusing the RNG validator when it scans
the DOM document?

I've got a test case that illustrates the behaviour.
I'm attaching the schema in RNC and RNG format, the Perl
demonstrating the behaviour, and the output from the
script.  I basically build the document by hand and run it
through the validator four times.  For each run, the output
contains the XML (from the document's toString() method),
the results of eval'ing validation on the document-as-modified,
and the results from validating a new document created from
the XML.

The last case shows that validation of the bad XML fails
as expected, but does *not* fail on the document from which
the XML was extracted.

Am I misusing the document manipulation mechanisms?  Or should
this work and I've found a bug?  Or what?

Thanks!
-- 
#ken	P-)}

Ken Coar, Sanagendamgagwedweinini  http://Ken.Coar.Org/
Author, developer, opinionist      http://Apache-Server.Com/

"Millennium hand and shrimp!"
Thread:
Rodent of Unusual Size
Rodent of Unusual Size
Petr Pajas
Rodent of Unusual Size
Petr Pajas
Vaclav Barta
Rodent of Unusual Size
Vaclav Barta

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved