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

Hi Monks,

I try to check well-form of the XML file(without entity expanstion, using "NoExpand" option), it is not working what is the problem?

Updated: I need this, if entity is appeared in that XML file, that declaration should be ignored. What is the way to do this?

<!ENTITY e SYSTEM “e.xml”> For example, &e; should not be replaced with corresponding entity.
I try with below code

use XML::Parser; my $xmlfile = do {local $/, <DATA>}; my $parser = XML::Parser->new( ErrorContext => 2, NoExpand => 1 ); eval { $parser->parsefile( $xmlfile ); }; if( $@ ) { print STDERR "\nERROR in '$xmlfile':\n$@\n"; } else { print STDERR "'$xmlfile' is well-formed\n"; } __DATA__ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE test [ <!ENTITY e SYSTEM "a.pl"> ]> <test> <customer> <first-name>J&e;oe</first-name> <surname>Wrigley</surname> <address> <street>17 Be&#x00DC;able Ave.</street> <city>Meatball</city> <state>MI</state> <zip>82649</zip> </address> <email>joewrigley@jmac.org</email> <age>42</age> </customer> <customer> <first-name>Henrietta</first-name> <surname>Pussycat</surname> <address> <street>R.F.D. 2</street> <city>Flangerville</city> <state>NY</state> <zip>83642</zip> </address> <email>meow@263A.org</email> <age>37</age> </customer> </test>

Thanks
Balaji. M

Replies are listed 'Best First'.
Re: NoExpand option in XML::Parser
by moritz (Cardinal) on Jul 09, 2008 at 13:19 UTC
    it is not working what is the problem?

    I'd like to know that as well. What output do you expect? what do you get?

    See also How (Not) To Ask A Question

    And please quote the XML sample with <code>...</code> tags.

    Update: When I run your code I get the message that a.pl can't be found (the one linked in your ENTITIY defintion). That makes it a bit hard to know what your error is.