[cxml-devel] cxml-stp usage
David Lichteblau
david at lichteblau.com
Sun Jun 10 10:49:12 UTC 2012
Hi,
Quoting Steven Nunez (steve_nunez at yahoo.com):
> Greetings all,
>
> I'm a bit stumped by some of the STP functions and usage. The documentation is, well, a bit sparse, so it's not clear whether there really is a bug or I'm mis-interpreting what I'm reading. Here is a simple function that should return all the child nodes of an element with the local-name of 'RegressionModel':
>
> (defun function-name (document)
> "Return the PMML model type of the document"
> (stp:filter-recursively (stp:of-name "RegressionModel") (stp:first-child document)))
The call to OF-NAME is the problem, it needs to be
(stp:of-name "RegressionModel" "http://www.dmg.org/PMML-4_0")
because:
> According to the documentation of filter-recursively:
> Return a list of descendant nodes of node in pre-order, from which nodes that do not satisfy predicate have been removed.and that for of-name:
> This function creates a test function for nodes of this name.
> >
> >The function returned will return T if the argument is an instance of attribute or element and has the specified local-name and namespace URI, and will return NIL otherwise.
> >
> >If local-name is nil, only the namespace URI is considered for comparison.
your element is in the http://www.dmg.org/PMML-4_0 namespace, whereas you
specified the empty namespace.
Roughly speaking,
local-name == SYMBOL-NAME
namespace-uri == SYMBOL-PACKAGE
I.e. just like distinct symbols in different packages have got nothing
to do with each other just because they happen to have the same
SYMBOL-NAME in Lisp, similarly in XML, two elements with the same
local-name but a different namespace are considered distinct.
> and here's the local snippet of the xmls that I'm trying to filter for:
[...]
> So, there's an attribute with a local-name that matches the value in
> of-name. Why is this function always returning NIL?
An element with that local-name, right?
> Is stp stable enough for production use? It's been a while since it's
> been updated. I'm new to XML with LISP, so if there's a better
> documented or easier way to process these documents, happy to take a
> different route.
I think STP was pretty much finished when it was first written, because
it is basically a Common Lisp adaptation of XOM, so the design was clear
from the start.
> Finally, does anyone know why I need to pass the function the first
> child? Seem cxml-stp is getting tripped up on the first line of the
> xml file: <?xml version="1.0" encoding="UTF-8"?> and forcing me to
> manually grab the second element. Is there a convention or idiom I'm
> missing?
I see no reason why you would have to call stp:first-child. The example
works without that call.
d.
More information about the cxml-devel
mailing list