Forum OpenACS Q&A: Re: Is this tDOM related?

Collapse
6: Re: Is this tDOM related? (response to 1)
Posted by Bjorn Thor Jonsson on

Now when I install from an updated cvs head checkout there are complaints in the error log about invalid command name "xml_doc_get_first_node_by_name". Checking packages/acs-tcl/tcl/30-xml-utils-procs.tcl I see the proc doesn't exist, as it does in a previous checkout. That proc might be implemented using tDOM like this:

# Get first node with a given name
proc xml_doc_get_first_node_by_name {doc_id name} {
    set root [$doc_id documentElement]
    return [$root child 1 $name]
}
Assuming that the first child of the root element with the given name is what you want. But the previous nsxml implementation seems to assume that you might also be searching for the root element by name, which just seems weird to me. Either you explicitly ask for the root element or search for one of it's decendants. But I guess that behaviour might be implemented by using domDoc's getElementsByTagName method.

It is lang::catalog::parse that is missing xml_doc_get_first_node_by_name. Since it is using it to get the message_catalog root element, I just changed it to use xml_doc_get_first_node instead.

But still there where errors. Changing the xml_parse proc in packages/acs-tcl/tcl/30-xml-utils-procs.tcl from

proc xml_parse args {
#   ns_log notice "xml_parse $args"
    if {[lindex $args 0] == "-persist"} {
        return [dom parse -simple [lindex $args 1]]
    } else {
        dom parse -simple [lindex $args 0] doc
        return $doc
    }
}
to
proc xml_parse args {
#   ns_log notice "xml_parse $args"
    if {[lindex $args 0] == "-persist"} {
        return [dom parse -simple [lindex $args 1]]
    } else {
        return [dom parse -simple [lindex $args 0]]
    }
}
fixed those. The DOM tree and the associated Tcl command object was probably being freed automatically: http://tdom.org/dom.html

Collapse
9: Re: Is this tDOM related? (response to 6)
Posted by Bart Teeuwisse on
Bjorn,

what appeared as a bug is actually intentional. You'll have to include the --persist flag in your call to xml_parse if you intend to avoid the automatic freeing of the DOM tree.

When I made the change, all of the package in OpenACS core used the --persist flag. I suggest changing the calling script. Or remove the --persist flag from xml_parse all together and always return a persistent DOM tree. Please note that persistent trees require explicit deletion.

I'll comment on the xml_doc_get_first_node_by_name after my return from NY.

/Bart