Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: How can i validate xml file?

by monkey_boy (Curate)
on Feb 23, 2006 at 16:03 UTC ( #532302=note: print w/ replies, xml ) Need Help??


in reply to How can i validate xml file?

Not perl, but if your on a linux os, then check if xmllint is installed, this can be used to validate your xml in superfast time,

system("xmllint --noout foo.xml") and die "Failed!";


This is not a Signature...


Comment on Re: How can i validate xml file?
Download Code
Re^2: How can i validate xml file?
by Anonymous Monk on Feb 23, 2006 at 16:23 UTC

    Hi monkey_boy,

    Thanks kool, It's working fine. But, I am getting xml content is it possible to check. And also, i am not allow here to use system function i want sample code.. For ex if i validate xml file with xsd file i use below code like i want code please

    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";

      If your input data is not well-formed XML (and I assume that's what you're asking about) then the parse_file call will die. Put a eval around that call and check the value in $@ after parse_file returns.

      --
      <http://dave.org.uk>

      "The first rule of Perl club is you do not talk about Perl club."
      -- Chip Salzenberg

Re^2: How can i validate xml file?
by Anonymous Monk on Feb 24, 2006 at 04:06 UTC

    Thanks monkey_boy, and davido now i get answer from davidrw answer chanceless thanks davidrw.

    use XML::LibXML; my $parser = XML::LibXML->new(); my $xml_text = eval { $parser->parse_string($text); }; print $@

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://532302]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (8)
As of 2014-10-25 16:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (145 votes), past polls