Lisp HUG Maillist Archive

& in file parsed by CXML

When I parse a file containing "&"s, CXML:parse-file gives the error message 
"Error: Document not well-formed: entity not defined: amp".  Maybe I need to 
provide more information to the parser about how to handle the XML special 
characters but I am not sure where to do that.

Here is an example:
REPL> (with-open-file (s "example.xml" :direction :output)
    (write-string "<test a='b&amp;'><child/></test>" s))

--> "<test a='b&amp;'><child/></test>"

REPL> (cxml:parse-file "example.xml" (cxml-xmls:make-xmls-builder))

--> Error: Document not well-formed: entity not defined: amp
Context:
  Line 1, column 16 in file://+

Without the &amp; it works fine and produces:
--> ("test" (("a" "b")) ("child" NIL))

Thanks for any help.
Mitch 


Re: & in file parsed by CXML

On Fri, 15 Sep 2006 15:00:26 -0400, "Mitch Berkson" <mitch@bermita.com> wrote:

> When I parse a file containing "&"s, CXML:parse-file gives the error
> message "Error: Document not well-formed: entity not defined: amp".
> Maybe I need to provide more information to the parser about how to
> handle the XML special characters but I am not sure where to do
> that.
>
> Here is an example:
> REPL> (with-open-file (s "example.xml" :direction :output)
>     (write-string "<test a='b&amp;'><child/></test>" s))
>
> --> "<test a='b&amp;'><child/></test>"
>
> REPL> (cxml:parse-file "example.xml" (cxml-xmls:make-xmls-builder))
>
> --> Error: Document not well-formed: entity not defined: amp
> Context:
>   Line 1, column 16 in file://+
>
> Without the &amp; it works fine and produces:
> --> ("test" (("a" "b")) ("child" NIL))

I don't think this is on topic for this mailing list, but anyway...

>From looking at the source code my guess is that ENSURE-DTD is called
too late in the P/DOCUMENT function.  You won't get this message if
the entity isn't in the first child:

  CL-USER 34 > (with-open-file (s "/tmp/example.xml" :direction :output :if-exists :supersede)
                 (write-string "<test a='b'><child a='b&amp;'/></test>" s))
  "<test a='b'><child a='b&amp;'/></test>"

  CL-USER 35 > (cxml:parse-file "/tmp/example.xml" (cxml-xmls:make-xmls-builder))
  ("test" (("a" "b")) ("child" (("a" "b&"))))

The CXML mailing list is here:

  http://common-lisp.net/cgi-bin/mailman/listinfo/cxml-devel

Cheers,
Edi.


Updated at: 2020-12-10 08:47 UTC