Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

How to check xml elements?

by gube (Parson)
on Jan 05, 2006 at 12:57 UTC ( [id://521189]=perlquestion: print w/replies, xml ) Need Help??

gube has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,

I have xml schema definition file and xml file and i have to check based on the xml schema definition the xml elements were defined. If xml elements is wrongly defined i want to know the element details.

So, can anyone please refer the modules, sample codes, links based on this using perl.

Thanks in Advance.

Regards,
Gube

Replies are listed 'Best First'.
Re: How to check xml elements?
by astroboy (Chaplain) on Jan 05, 2006 at 13:49 UTC
    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.

      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

Re: How to check xml elements?
by Joost (Canon) on Jan 05, 2006 at 13:02 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://521189]
Approved by Joost
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-25 09:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found