Reporting from XML documents in RS 2005
Recently, I’ve come across a question on the RS public newsgroup about how to use the new RS 2005 XML extension to report off relative nodes in an XML document. The attached sample demonstrates this scenario. For example, given this document:
<bookstore xmlns=”http://example.books.com“>
<book genre=”autobiography” publicationdate=”1981″ ISBN=”1-861003-11-0″>
<title>The Autobiography of Benjamin Franklin</title>
<author>
<first-name>Benjamin</first-name>
<last-name>Franklin</last-name>
</author>
<date>09-06-1956</date>
<samplechapters>1 3 4</samplechapters>
<price alternative=”discount”>5.99</price>
<price>8.99</price>
</book>
<book genre=”autobiography” publicationdate=”1972″ ISBN=”0399105573″>
<title>The Moon’s a Balloon</title>
<author>
<first-name>David</first-name>
<last-name>Niven</last-name>
</author>
<date>09-06-1974</date>
<samplechapters>4 5</samplechapters>
<price alternative=”discount”>1.94</price>
<price>2.57</price>
</book>
</bookstore>
The following query fetches the book/title, book/author/first-name, and book/date elements, as well as book/@publication date.
bookstore/book {title, author{first-name}, @publicationdate, date}
In my opinion, it could have been nice if you were able to use XPATHs to bring the elements needed instead of this pseudo syntax that relies on curly brackets. Another potential area of improvement is supporting XML schemas to cast the column types automatically according to the defined schema types. As it stands, the XML extension returns all columns as of string date type. However, you can explicitly cast the column type to another type. For example, assuming that the publication attribute returns a valid date:
bookstore/book {title, author{first-name}, @publicationdate(date), date}
will cast the publicationdate column to a date data type.