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

All,

I have an XML document with an external parameter entity in the doctype. When I use toString on the XML::LibXML document object, this entity is being expanded in the doctype. Is there any way to turn expansion off on such entities? I am alreadying turning off the expand_entities option, and it works throughout the rest of the document, but this seems not to impact the the doctype tag.

Here is some sample XML, demonstrating what I am talking about:

<?xml version="1.0" standalone="no"?> <!DOCTYPE student [ <!ENTITY % student SYSTEM "http://www.university.com/student.dtd"> %student; ]>

Using the provided example, "%student;" is being replaced by the contents of the entity when I print out the document. I would like to be able to print the doctype tag in the same format that it was provided (i.e. unexpanded).

Here are the parameters that I am passing to the LibXML parser:

$parser->line_numbers(1); $parser->validation(0); $parser->load_ext_dtd(1); $parser->expand_entities(0);

Please let me know if there is any other information that I could provide that would prove useful, and thanks for your consideration.

Replies are listed 'Best First'.
Re: Suppressing XML::LibXML External Parameter Entity Expansion
by ikegami (Patriarch) on Mar 29, 2010 at 21:27 UTC
    Sounds like you should replace
    <!DOCTYPE student [ <!ENTITY % student SYSTEM "http://www.university.com/student.dtd"> %student; ]>
    with
    <!DOCTYPE student SYSTEM "http://www.university.com/student.dtd">

    I am [already] turning off the expand_entities option, and it works throughout the rest of the document

    And you might want to place a bug report.

      A co-worker pointed out that the XML example that I used was not the best. It is not actually the DTD that is being included as an entity, but rather an external entity file. Here is a better example of the XML:

      <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE studentPackage [ <!ENTITY % StudentEntities PUBLIC "ISO 9999-9999//ENTITIES Student C +haracter Entities 20100330//EN//XML" "http://www.student.org/Student_ +1-0/ent/StudentEntities"> %StudentEntities; ]>
Re: Suppressing XML::LibXML External Parameter Entity Expansion
by scotth (Initiate) on Apr 06, 2010 at 12:19 UTC
    Just in case anyone was curious, I ended up using a regex to store the original doctype tag. After this, I did my LibXML processing. Finally, I restored the original doctype, using a substition regex, after LibXML processing was complete. This is not the ideal solution, but it is the best that I have for now.
Re: Suppressing XML::LibXML External Parameter Entity Expansion
by Anonymous Monk on Mar 14, 2013 at 23:49 UTC
    Have same issue here