Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl XML-SAX-Expat external entity location

I am using XML-Simple along with XML-SAX-Expat to parse a document with external entities. I declare my entity like:

<!ENTITY chap1 SYSTEM "chapter-1.xml">

And I refer to from another file in the same directory.

However, it is searching my current working directory for the file, and not the location of the root document.

404 File `/u/egge/chapter-1.xml' does not exist

Handler couldn't resolve external entity at line 35, column 2, byte 1040
error in processing external entity reference at line 35, column 2, byte 1040 at     /perl5/PROJ/XML-Parser/2.36-2.0.1-5.10-64/lib/perl5/XML/Parser.pm line 187

How can I get it to use the root document's directory instead of my CWD?

like image 313
brianegge Avatar asked Jan 26 '26 03:01

brianegge


1 Answers

The utility xmllint has the --noent flag, that will expand the ENTITY references of the root document. If you can't find an alternative, you could always rewrite the input file quickly with this:

xmllint --noent $input.xml > expanded.xml

It also has the advantage of precomputing the full XML file, rather than doing it each time at runtime.

like image 83
tlrrd Avatar answered Jan 28 '26 18:01

tlrrd