in reply to How to check xml elements?

You can do it with XML::LibXML. Make sure that you have the latest libxml2 library installed (http://xmlsoft.org/), as it has improved schema validation. For instance, Redhat Linux came with an older version of libxml2, so I installed the latest version from source. The default location is different to the standard Linux build, so I reinstalled XML::LibXML and XML::LibXML::Common to point to it.
use XML::LibXML; my $schema_file = 'po.xsd'; my $document = 'po.xml'; my $schema = XML::LibXML::Schema->new(location => $schema_file); my $parser = XML::LibXML->new; my $doc = $parser->parse_file($document); eval { $schema->validate($doc) }; die $@ if $@; print "$document validated successfully\n";
For some reason, this is not documented in the POD (which is why almost no one knows about XML:LibXML's schema validation powers!), but the XML::LibXML source comes with the documentation in docbook format plus a utility to generate the POD from that.

Replies are listed 'Best First'.
Re^2: How to check xml elements?
by gube (Parson) on Jan 09, 2006 at 10:47 UTC

    Hi Joost/astroboy,

    Thanks for your comments. Joost, saying XML::Schema::Validator does not work with elementFormDefault="qualified" and it also not supported various tags as mentioned in the POD. But, I want to support all the valid xml tags and elements as supported by the tools.

    The XML::LibXML is working fine. But, it's a system package and I do not want to install anything dependent on system packages. The application would run in an secure environment and there won't be many packages installed on it. So, if any perl modules in that validation found please help me.
    Thanks in Advance.
    Regards,
    Gube

      Hi, these seem to be your options:
      1. XML::Schema::Validator - nice, but does not offer complete validation functionality, but good for many people's requirements.
      2. XML::Xerces - I could never get everything installed and working
      3. XML::LibXML - clean and simple

      I'm afraid that at some point you're gonna have to bite the bullet and go for option three if you need validation