[plexippus-xpath-devel] parsed input != serialized output?

rm at tuxteam.de rm at tuxteam.de
Sun Nov 28 20:02:49 UTC 2010


On Sun, Nov 28, 2010 at 02:14:06PM -0500, Andrei Stebakov wrote:
> Hello
> 
> I wonder if parse/serialize should arrive at the same string given to
> the parser?


But that's impossible _unless_ you restrict yourself to canonic xml.

> Let's say
> 
> (let ((sink (cxml:make-string-sink)))
>   (stp:serialize (chtml:parse "<p><div>some text</div></p>"
> (stp:make-builder)) sink)
>   (sax:end-document sink))
> 
> I would expect the result to be "<p><div>some text</div></p>", but
> instead it's "<p/><div>some text</div>" (with some <?xml ...>
> headers).
> Why would it rearrange the <p> tag in this manner? What other kinds of
> re-arrangement to expect?

But it doesn't! You parse _html_ where '<p>' -> '<p/>' ...
Parse your string as xml and you get what you want:

(let ((sink (cxml:make-string-sink)))
  (stp:serialize (cxml:parse "<p><div>some text</div></p>"
(stp:make-builder)) sink)
  (sax:end-document sink))

"<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<p><div>some text</div></p>"

 HTH Ralf Mattes

> 
> Thank you,
> Andrew
> 
> _______________________________________________
> plexippus-xpath-devel mailing list
> plexippus-xpath-devel at common-lisp.net
> http://common-lisp.net/cgi-bin/mailman/listinfo/plexippus-xpath-devel




More information about the plexippus-xpath-devel mailing list