[cxml-devel] Bugs when working with document nodes
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, Excellent job on cxml! I have unfortunately run into a couple of problems using version 2006-01-05. I don't know if they are known issues... 1. clone-node when applied to a document doesn't work. 2. create-document does not set the dtd of a document based on the supplied document type definition. This for example inhibits get-element-by-id from working. Thanks, Sunil -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.1 (Cygwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFE41ErjRnqWMAEf1cRArMuAJ0TNTRzVBtq66SvBeJH9TLGY4z0lQCdHEdJ 445BRIzteFY8mPBxIQCIcW0= =bCp7 -----END PGP SIGNATURE-----
Quoting Sunil Mishra (smishra@sfmishras.com):
1. clone-node when applied to a document doesn't work.
Aha. The spec says something about implementation-dependent behaviour when cloning documents. I have not investigated what other DOM implementations are doing here, but creating a new document referencing the same DTD data structures seems like a good idea. I will implement that and let you know when it is done.
2. create-document does not set the dtd of a document based on the supplied document type definition. This for example inhibits get-element-by-id from working.
create-document is indeed a very simple function that just creates a new document without any DTD information, similar to the result of parsing an "empty" XML document into DOM. I'm not sure I understand what precise behaviour you expect from create-document or how to implement it. Can you elaborate? d.
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 David Lichteblau wrote:
Quoting Sunil Mishra (smishra@sfmishras.com):
1. clone-node when applied to a document doesn't work.
Aha. The spec says something about implementation-dependent behaviour when cloning documents. I have not investigated what other DOM implementations are doing here, but creating a new document referencing the same DTD data structures seems like a good idea.
I will implement that and let you know when it is done.
Excellent! Thank you!
2. create-document does not set the dtd of a document based on the supplied document type definition. This for example inhibits get-element-by-id from working.
create-document is indeed a very simple function that just creates a new document without any DTD information, similar to the result of parsing an "empty" XML document into DOM.
I'm not sure I understand what precise behaviour you expect from create-document or how to implement it. Can you elaborate?
At present there is no API for setting the DTD of a document. Given that some dom functions (such as get-node-from-id or something like that) rely on having a dtd to determine which attribute is in fact an id, seems that having a dtd in a document is quite important. Looking at this from another point of view, when you write an xhtml document, you have the following preamble: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> When an xml document with this preamble is parsed, cxml sees the doctype and registers the xhtml dtd, parsing the document at http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd. There is no such thing that happens when you create a document and supply a document type node explicitly, even though create-document-type takes as two of its arguments the public-id -//W3C//DTD XHTML 1.0 Strict//EN and the system-id http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd. Would it not be reasonable to have a document using this document type to also reference the same DTD object, as it would had it been parsed from a file? Hope my request and motivation are clearer. Sunil -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.1 (Cygwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFE442cjRnqWMAEf1cRAhagAKC3t/5muGk692xabadfWZIEiQOx1ACgrPXg ZITJkmntP8v80xQJUNKSCEs= =lElp -----END PGP SIGNATURE-----
Quoting Sunil Mishra (smishra@sfmishras.com):
2. create-document does not set the dtd of a document based on the supplied document type definition. This for example inhibits get-element-by-id from working.
Oh, browsing the DOM specification for ideas I just found out that cxml does not implement the DOMImplementation interface at all. What you are looking for is DOMImplementation.createDocument(), right? It just happens that cxml has a function called CREATE-DOCUMENT with utterly different and less useful behaviour for historical reasons. Not sure why the test suite never caught that, but we claim to implement DOM 2 now, so I will fix that. interface DOMImplementation { [...] // Introduced in DOM Level 2: DocumentType createDocumentType(in DOMString qualifiedName, in DOMString publicId, in DOMString systemId) raises(DOMException); // Introduced in DOM Level 2: Document createDocument(in DOMString namespaceURI, in DOMString qualifiedName, in DocumentType doctype) raises(DOMException); [...] } d.
Quoting David Lichteblau (david@lichteblau.com):
It just happens that cxml has a function called CREATE-DOCUMENT with utterly different and less useful behaviour for historical reasons. Not sure why the test suite never caught that, but we claim to implement DOM 2 now, so I will fix that.
Oops. My apologies, I looked at the wrong version of the source code. The cxml fork we are using here doesn't have DOM 2's DOMImplementation yet, but the common-lisp.net version has it, of course . All in good order. And you are right, (dom:create-document 'dom:implementation uri qname doctype) creates a document with a doctype, but not a cxml DTD object. Hmm.
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi David, It looks like clone-node on a document doesn't work with the attached document... CL-USER(11): (describe /d) #<RUNE-DOM::DOCUMENT @ #x20cdf832> is an instance of #<STANDARD-CLASS RUNE-DOM::DOCUMENT>: The following slots have :INSTANCE allocation: PARENT NIL CHILDREN #(#<RUNE-DOM::ELEMENT svg @ #x20cf46ea>) OWNER NIL READ-ONLY-P NIL MAP NIL DOC-TYPE #<RUNE-DOM::DOCUMENT-TYPE @ #x20ced59a> DTD #S(CXML::DTD :ELEMENTS #<EQUAL hash-table with 81 entries @ #x20cf248a> :GENTITIES #<EQUAL hash-table with 5 entries @ #x20cf24ba> :PENTITIES #<EQUAL hash-table with 707 entries @ #x20cf24ea> :NOTATIONS #<EQUAL hash-table with 0 entries @ #x20cf251a>) ENTITY-RESOLVER #<Closure (:INTERNAL CXML::P/DOCTYPE-DECL 1) @ #x20ced5d2> CL-USER(14): (dom:map-document (cxml:make-namespace-normalizer (cxml:make-octet-stream-sink *standard-output*)) /d :include-doctype :canonical-notations) <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> ; <defs> <rect fill="black" height="10" id="default-node-shape" stroke="blue" width="60"></rect> </defs> </svg> #<MULTIVALENT stream socket connected from localhost/3982 to localhost/3983 @ #x205003d2> CL-USER(15): (dom:clone-node /d t) Error: The slot DOM::%INTERNAL-SUBSET is unbound in the object #<RUNE-DOM::DOCUMENT-TYPE @ #x208cd3e2> of class #<STANDARD-CLASS RUNE-DOM::DOCUMENT-TYPE>. [condition type: UNBOUND-SLOT] Restart actions (select using :continue): 0: Try accessing the slot again 1: Return a value 2: Store a value and return it 3: Return to Top Level (an "abort" restart). 4: Abort entirely from this (lisp) process. [1] CL-USER(16): :zo Evaluation stack: (ERROR #<UNBOUND-SLOT @ #x209b9542>) ->((METHOD SLOT-UNBOUND (T T T)) #<STANDARD-CLASS CXML-DOM::DOCUMENT-TYPE> #<CXML-DOM::DOCUMENT-TYPE @ #x208cd3e2> ...) ((METHOD DOM:CLONE-NODE (CXML-DOM::DOCUMENT T)) #<CXML-DOM::DOCUMENT @ #x208c1692> T) (EVAL (DOM:CLONE-NODE /D T)) (TPL:TOP-LEVEL-READ-EVAL-PRINT-LOOP) (TPL:START-INTERACTIVE-TOP-LEVEL #<MULTIVALENT stream socket connected from localhost/3982 to localhost/3983 @ #x205003d2> TPL:TOP-LEVEL-READ-EVAL-PRINT-LOOP ...) [1] CL-USER(17): :pop Sunil David Lichteblau wrote:
Quoting David Lichteblau (david@lichteblau.com):
Quoting Sunil Mishra (smishra@sfmishras.com):
1. clone-node when applied to a document doesn't work. I will implement that and let you know when it is done.
Checked in, please test!
d. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.1 (Cygwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFE6zhGjRnqWMAEf1cRAsSRAKCnQi2YB525G/PM2G0YCf1bBWdJRACgnYTG wYqIK3gHQmbCAlu74y4Jq7M= =s5T2 -----END PGP SIGNATURE-----
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi David, Looks like we're getting closer. Again, with reference to the graph.xml I had previously attached... clone-node is sort of working. It looks like it is making all the attributes that had previously been implicit, explicit. They are all being output in the svg element after cloning the document. Also note that I'm still getting xlink=.... rather than xmlns:xlink=.... in the cloned document. This does not happen when I output the original document. I am using Allegro CL 7.0, you had guessed correctly. And I did a CVS update and recompiling cxml before testing any of this. Thank you for working with me in resolving these bugs. Sunil CL-USER(11): (cxml:parse-file #p"C:\\graph.xml" (rune-dom:make-dom-builder) :entity-resolver #'entity-resolver) #<RUNE-DOM::DOCUMENT @ #x210866f2> CL-USER(12): (dom:map-document (cxml:make-namespace-normalizer (cxml:make-octet-stream-sink *standard-output*)) (dom:clone-node * t) :include-doctype :canonical-notations) <svg contentScriptType="text/ecmascript" contentStyleType="text/css" preserveAspectRatio="xMidYMid meet" version="1.1" xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" zoomAndPan="magnify"> <defs> <rect fill="black" height="10" id="default-node-shape" stroke="blue" width="60"></rect> </defs> </svg> #<MULTIVALENT stream socket connected from TEA/2292 to TEA/2293 @ #x205f078a> David Lichteblau wrote:
Quoting Sunil Mishra (smishra@sfmishras.com):
It looks like clone-node on a document doesn't work with the attached document... ... with a doctype but without an internal subset.
Thank you, bugfix checked in.
d. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.1 (Cygwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFE8it7jRnqWMAEf1cRApClAJ9Eo7YZjjEI66X/NGC8Mvy6cJ7wrgCgzsSr NmUCkiLgV4owKxnahYSsF0E= =qSFG -----END PGP SIGNATURE-----
Quoting Sunil Mishra (smishra@sfmishras.com):
clone-node is sort of working. It looks like it is making all the attributes that had previously been implicit, explicit. They are all being output in the svg element after cloning the document.
Also note that I'm still getting xlink=.... rather than xmlns:xlink=.... in the cloned document. This does not happen when I output the original document.
Oops, I am losing faith in the DOM test suite... Attribute nodes got imported with some slots missing, it should have caught that. Thank you for the report. Fix checked in; I am now getting the exact same output: <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> ; <defs> <rect fill="black" height="10" id="default-node-shape" stroke="blue" width="60"></rect> </defs> </svg> for all of these: (dom:map-document (cxml:make-octet-stream-sink *standard-output*) /d :include-doctype :canonical-notations) (dom:map-document (cxml:make-octet-stream-sink *standard-output*) (dom:clone-node /d t) :include-doctype :canonical-notations) (dom:map-document (cxml:make-namespace-normalizer (cxml:make-octet-stream-sink *standard-output*)) /d :include-doctype :canonical-notations) (dom:map-document (cxml:make-namespace-normalizer (cxml:make-octet-stream-sink *standard-output*)) (dom:clone-node /d t) :include-doctype :canonical-notations) Phew. :-) d.
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Perfect! Whatever changes you made the last time around, they have also fixed my xmlns declaration problem. Thank you so much. Sunil David Lichteblau wrote:
Quoting Sunil Mishra (smishra@sfmishras.com):
clone-node is sort of working. It looks like it is making all the attributes that had previously been implicit, explicit. They are all being output in the svg element after cloning the document.
Also note that I'm still getting xlink=.... rather than xmlns:xlink=.... in the cloned document. This does not happen when I output the original document.
Oops, I am losing faith in the DOM test suite... Attribute nodes got imported with some slots missing, it should have caught that. Thank you for the report.
Fix checked in; I am now getting the exact same output:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> ; <defs> <rect fill="black" height="10" id="default-node-shape" stroke="blue" width="60"></rect> </defs> </svg>
for all of these:
(dom:map-document (cxml:make-octet-stream-sink *standard-output*) /d :include-doctype :canonical-notations)
(dom:map-document (cxml:make-octet-stream-sink *standard-output*) (dom:clone-node /d t) :include-doctype :canonical-notations)
(dom:map-document (cxml:make-namespace-normalizer (cxml:make-octet-stream-sink *standard-output*)) /d :include-doctype :canonical-notations)
(dom:map-document (cxml:make-namespace-normalizer (cxml:make-octet-stream-sink *standard-output*)) (dom:clone-node /d t) :include-doctype :canonical-notations)
Phew. :-)
d. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.1 (Cygwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFE9dHvjRnqWMAEf1cRAoyDAJ0YaMOzbNICJd79ar61tTPfSbumxQCgoKGl 04maWaGea2JTs5bDKlqukKs= =R9jX -----END PGP SIGNATURE-----
Hi, Quoting Sunil Mishra (smishra@sfmishras.com):
2. create-document does not set the dtd of a document based on the supplied document type definition. This for example inhibits get-element-by-id from working.
I am not convinced that DOMImplementation.createDocumentType() is meant to go and start parsing DTDs. Instead, I have implemented a new function CXML:PARSE-EMPTY-DOCUMENT, which will look for DTDs like the other parser functions do, and that can be used together with a DOM builder to create a new DOM document. I hope that works for you; please test! Example below. Thanks, David -------- CL-USER(52): (cxml:parse-empty-document #"http://www.w3.org/1999/xhtml" #"html" (cxml-dom:make-dom-builder) :public-id #"-//W3C//DTD XHTML 1.0 Transitional//EN" :system-id #u"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd") #<UTF8-DOM::DOCUMENT {BD01A19}> CL-USER(53): (describe *) #<UTF8-DOM::DOCUMENT {BD01A19}> is an instance of class #<STANDARD-CLASS UTF8-DOM::DOCUMENT>. The following slots have :INSTANCE allocation: PARENT NIL CHILDREN #(#<UTF8-DOM::ELEMENT html {C1EE099}>) OWNER NIL READ-ONLY-P NIL MAP NIL DOC-TYPE #<UTF8-DOM::DOCUMENT-TYPE {BD02001}> DTD #S(CXML::DTD :ELEMENTS #<HASH-TABLE :TEST EQUALP :COUNT 89 {BD074B9}> :GENTITIES #<HASH-TABLE :TEST EQUALP :COUNT 253 {BD076A9}> :PENTITIES #<HASH-TABLE :TEST EQUALP :COUNT 68 {BD07899}> :NOTATIONS #<HASH-TABLE :TEST EQUALP :COUNT 0 {BD07A89}>) ENTITY-RESOLVER #<CLOSURE (LAMBDA (CXML::N CXML::H)) {C1ED945}> CL-USER(54): (describe (dom:doctype **)) #<UTF8-DOM::DOCUMENT-TYPE {BD02001}> is an instance of class #<STANDARD-CLASS UTF8-DOM::DOCUMENT-TYPE>. The following slots have :INSTANCE allocation: PARENT NIL CHILDREN #() OWNER #<UTF8-DOM::DOCUMENT {BD01A19}> READ-ONLY-P NIL MAP NIL NAME "html" PUBLIC-ID "-//W3C//DTD XHTML 1.0 Transitional//EN" SYSTEM-ID "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" ENTITIES #<UTF8-DOM::NAMED-NODE-MAP {BD01FD1}> NOTATIONS #<UTF8-DOM::NAMED-NODE-MAP {BD01FA9}> %INTERNAL-SUBSET "unbound"
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi David, David Lichteblau wrote:
Hi,
Quoting Sunil Mishra (smishra@sfmishras.com):
2. create-document does not set the dtd of a document based on the supplied document type definition. This for example inhibits get-element-by-id from working.
I am not convinced that DOMImplementation.createDocumentType() is meant to go and start parsing DTDs.
I agree. I had meant that createDocument might do the DTD parsing.
Instead, I have implemented a new function CXML:PARSE-EMPTY-DOCUMENT, which will look for DTDs like the other parser functions do, and that can be used together with a DOM builder to create a new DOM document.
This sounds good too. I'll try it out. Sunil
I hope that works for you; please test!
Example below.
Thanks, David -------- CL-USER(52): (cxml:parse-empty-document #"http://www.w3.org/1999/xhtml" #"html" (cxml-dom:make-dom-builder) :public-id #"-//W3C//DTD XHTML 1.0 Transitional//EN" :system-id #u"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd") #<UTF8-DOM::DOCUMENT {BD01A19}> CL-USER(53): (describe *) #<UTF8-DOM::DOCUMENT {BD01A19}> is an instance of class #<STANDARD-CLASS UTF8-DOM::DOCUMENT>. The following slots have :INSTANCE allocation: PARENT NIL CHILDREN #(#<UTF8-DOM::ELEMENT html {C1EE099}>) OWNER NIL READ-ONLY-P NIL MAP NIL DOC-TYPE #<UTF8-DOM::DOCUMENT-TYPE {BD02001}> DTD #S(CXML::DTD :ELEMENTS #<HASH-TABLE :TEST EQUALP :COUNT 89 {BD074B9}> :GENTITIES #<HASH-TABLE :TEST EQUALP :COUNT 253 {BD076A9}> :PENTITIES #<HASH-TABLE :TEST EQUALP :COUNT 68 {BD07899}> :NOTATIONS #<HASH-TABLE :TEST EQUALP :COUNT 0 {BD07A89}>) ENTITY-RESOLVER #<CLOSURE (LAMBDA (CXML::N CXML::H)) {C1ED945}> CL-USER(54): (describe (dom:doctype **)) #<UTF8-DOM::DOCUMENT-TYPE {BD02001}> is an instance of class #<STANDARD-CLASS UTF8-DOM::DOCUMENT-TYPE>. The following slots have :INSTANCE allocation: PARENT NIL CHILDREN #() OWNER #<UTF8-DOM::DOCUMENT {BD01A19}> READ-ONLY-P NIL MAP NIL NAME "html" PUBLIC-ID "-//W3C//DTD XHTML 1.0 Transitional//EN" SYSTEM-ID "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" ENTITIES #<UTF8-DOM::NAMED-NODE-MAP {BD01FD1}> NOTATIONS #<UTF8-DOM::NAMED-NODE-MAP {BD01FA9}> %INTERNAL-SUBSET "unbound"
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.1 (Cygwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFE6dBJjRnqWMAEf1cRAvsQAKDW4pywdLCi7DcE0cmV+8UqcpYOXQCeIQAJ Wc2E79hPviL/tLgwLWvknCM= =WX17 -----END PGP SIGNATURE-----
participants (2)
-
David Lichteblau
-
Sunil Mishra