0

I am Validating many XML files against the given XSD. It is printing some errors in Command line. I need that errors into one variable.

I am using Perl. I tried below things, but couldn't able to get the my requirement.

$values = system("xmlstarlet val --err --xsd Test.xsd Test1.xml");

return as 0 or 1

$values = `xmlstarlet val --err --xsd Test.xsd Test1.xml`

Errors looks like this

test.xml:5340.23: Element 'SP': This element is not expected.

It is printing only valid or invalid, I need above mentioned error also.

I used the following command

**xmlstarlet val --err --xsd Test.xsd Test1.xml** 

Let me know some ideas to get the errors.

Denim Datta
  • 3,740
  • 3
  • 27
  • 53
Umesha D
  • 826
  • 1
  • 7
  • 14

1 Answers1

1

Try this code;

my $error; 
my $values = `xmlstarlet val --err --xsd Test.xsd Test1.xml 2>&1`;

if ($?) {
    $error = $values;
}
glebaty
  • 200
  • 8