Invalid broadcast handler output in Common Lisp Closure XML package

Following the answers to my last question How do I embed elements in character content using Closure XML? I implemented a subclass of cxml: sax-proxy handler (a specific case of a broadcast handler). Unfortunately, it looks like an error in the library, but it is trying to create XML with internal document type definitions, but the document is not valid XML.

That is, by starting the parser with the command:

(with-open-file (out #P"teste.xml" :if-exists :supersede :direction :output) (let ((h (make-instance 'preproc :chained-handler (cxml:make-character-stream-sink out)))) (cxml:parse #P"harem.xml" h :validate t))) 

where the harem.xml file begins (see doctype):

 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE colHAREM SYSTEM "harem.dtd"> <colHAREM versao="Segundo_dourada_com_relacoes_14Abril2010"> <DOC DOCID="H2-dftre765"> <p>... 

the command produces in the output file teste.xml:

 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE colHAREM SYSTEM "harem.dtd"<!ELEMENT EM #PCDATA> <!ATTLIST EM ID CDATA #REQUIRED> <!ATTLIST EM CATEG CDATA #IMPLIED> <!ATTLIST EM TIPO CDATA #IMPLIED> <!ATTLIST EM COMENT CDATA #IMPLIED> <!ATTLIST EM SUBTIPO CDATA #IMPLIED> <!ELEMENT ALT (#PCDATA|EM)*> <!ELEMENT OMITIDO (#PCDATA|EM|ALT|p)*> <!ELEMENT colHAREM (DOC)*> <!ATTLIST colHAREM versao CDATA #REQUIRED> <!ELEMENT p (#PCDATA|EM|OMITIDO|ALT)*> <!ATTLIST p xml:space (default|preserve) "default"> <!ELEMENT DOC (#PCDATA|p|OMITIDO)*> <!ATTLIST DOC DOCID CDATA #REQUIRED> > <colHAREM versao="Segundo_dourada_com_relacoes_14Abril2010"> ... 

That is, the handler writes the DTD inside the output, but not so, without declarations inside [ and ] . Is this a bug in the library or in my code?

+5
source share
1 answer

I followed the steps that CXML takes for your example and prepared the patch here (the first file, against the last CXML commit, 991fac513dbd9b86628f99741a66d791552b1f02, apply with git apply 0001-....patch in the root of the checked CXML repository). It seems to me that the code path here simply does not trigger the SAX event for a subset of the DTD, so after adding that the output has the necessary "[" / "]" .

Can you confirm that this works for you? I'm also not sure SAX:START-INTERNAL-SUBSET is actually correct, but it seems to work here.

+2
source

Source: https://habr.com/ru/post/1206173/


All Articles