You're forgiven :p. I spend a weekend doing other stuff than hanging
behind the computer for a change, so therefor the reply is somewhat
late. Anyway, best this is to ask this on the on our mailing list
mysql-udf-...@googlegroups.com.
The sourceforge project is closed and the lib has moved to the
repository for mysql udfs. If you visit
'http://libmyxql.sourceforge.net', you're redirected (twice) to the
correct site. This means that the correct syntax is on the mysqludf.com
site.
I'll take take you through the 3 most important functions:
xql_element(name, content, attribute, attribute, ...), writes one
complete XML node, which has a (tag)name, content and multiple
attributes. The name is required and should be a string containing only
word chars, dashes and optionally a ':' (for namespace). The content may
be NULL, which will make a node like <name att="value" />, normal
content which is automatically escaped or raw XML which is not escaped.
Output from another xql function is automatically detected an seen a raw
XML. However it you want to add XML from a table or from a subquery, you
need use the special alias `xql:raw`, like xql_element("name", myxml AS
`xql:raw`).
xql_forest(...), writes multiple XML nodes, without any attributes.
The field name or alias will be the tag name and the value will be the
content (and is automatically escaped). xql_forest(first_name,
last_name, IF(gender=1, 'male', 'female') AS gender), would give you
(for 1 row),
"<first_name>Jan</first_name><last_name>Klaassen</last_name><gender>male</gender>".
Note that this is not valid XML, since there is no document root, the
lib doesn't force valid XML. You might want to put the whole thing in a
node though, you could use xql_element for that, however (also for
performance) you can also use the special alias `xql:root` for this.
Example: xql_forest("person" AS `xql:root`, first_name, last_name,
IF(gender=1, 'male', 'female') AS gender), would give you (for 1 row),
"<person><first_name>Jan</first_name><last_name>Klaassen</last_name><gender>male</gender></person>".
xql_agg(...), is almost like xql_forest, except that is aggregates the
data, which means it sticks data from different rows together, like
GROUP_CONCAT. The special alias `xql:root` will put a starting and
closing tag around all of the aggregated data, where `xql:child` puts a
starting and closing tag around each row before it is aggregated.
I hope it is now clear to you.
Good luck,
Arnold
Nat Woodard wrote:
> Please forgive me if you have already received this, I was having
> difficulty establishing a current email address for you. -nat
>
> Hi Arnold,
>
> I am in need of some help and hoping you don't mind me asking you for
> some clarification. I am working on some projects where I have
> recently decided to convert to an xml/xslt approach. In researching
> the best/most efficient way to get xml out of mysql is to use your
> libmyxql library. I had my server admin install the library and have
> been successful in getting a single root node with null child nodes
> (containing attributes). I cannot seem to figure out how to get child
> elements nested in the first element.
>
> When I initially came across your library I ended up with 2 different
> bookmarks to API references. They differ slightly. Can you confirm for
> me which API reference I should be using/learning? I have included
> links to the 2 API refs as well as the two differing examples of a
> result tree. (Please note that I am a designer who has learned more
> code than the average — but I still an idiot when it comes to
> understanding/recognizing syntax etc).
>
>
> Thanks for your time,
>
> -nat
>
> http://www.mysqludf.org/lib_mysqludf_xql/index.php
>
> Simple tree result
> SELECT xql_agg('classes' AS `xql:root`, `schoolclasses` AS `xql:raw`)
> FROM
> (SELECT xql_element('class', xql_agg('pupil' AS `xql:child`,
> firstname, lastname)), concat(grade, suffix) AS `name`, teacher) AS
> `schoolclasses` FROM schoolclass LEFT JOIN pupil ON schoolclass.id =
> pupil.schoolclass_id WHERE grade = 3 GROUP BY schoolclass.id) AS
> schoolclass
>
> http://libmyxql.sourceforge.net/examples.php
>
> SELECT xql_agg_root('classes', class_node) FROM
> (SELECT xql_root('class', xql_agg(xql_forest_el('pupil', 'firstname',
> firstname, 'lastname', lastname)), 'name', concat(grade, suffix),
> 'teacher', teacher) AS class_node FROM schoolclass LEFT JOIN pupil ON
> schoolclass.id = pupil.schoolclass_id WHERE grade = 3 GROUP BY
> schoolclass.id) AS x