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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With