N. America: 800 876 3101 | World: 44 (0) 1753 218 930

XML Publishing Functions

xmlelement()
Creates an XML element, allowing the name to be specified.
xmlattributes()
Creates XML attributes from columns, using the name of
each column as the name of the corresponding attribute.
xmlroot()
Creates the root node of an XML document.
xmlcomment()
Creates an XML comment.
xmlpi()
Creates an XML processing instruction.
xmlparse()
Parses a string as XML and returns the resulting XML structure.
xmlforest()
Creates XML elements from columns, using the name of each column as the name of the corresponding element.
xmlconcat()
Combines a list of individual XML values to create a single value containing an XML forest.
xmlagg()
Combines a collection of rows, each containing a single XML value, to create a single value containing an XML forest.

Let's compare a traditional SQL query with one that uses an XML publishing function. Here is a traditional SQL query that shows customers and their associated projects:

Here is is an excerpt of the result:

Now let's wrap the result in XML elements using xmlelement(), one of the publishing functions:

Each row in the result contains one Customer element. A Customer element looks like this:

xmlforest() is an XML publishing function that creates elements from a list of columns, using the name of the column as the name of the element. Using xmlforest() simplifies many queries significantly. For instance, the following query is equivalent to the previous one:

Now suppose we want to show customers and the projects associated with them. This is easily done with the following SQL query:

However, the result of this query is that shown in the CustomerProject table in the previous section, with one row for each Customer/Project pair. If a customer is associated with more than one project, there will be a row for that customer for each project. Here is a SQL/XML query that creates the XML equivalent to that table:

Here are the results of this query:

This is a straightforward XML translation of the that a SQL result set shown in the previous section, but for most XML applications it is not what we would want. Instead, we want to represent each customer once, with a list of that customer's projects, as shown in the XML output in the previous section. In SQL/XML, this can be done by using a sub-query. Here is a subquery that retrieves the projects associated with each customer. In this subquery we use xmlattributes(), an XML publishing function that creates attributes within an element. The names of the attributes are taken from the names of the columns.

Here is the output of the above sub-query when c.CustId is 4:

This output contains two rows, with one element in each row. Subqueries in SQL/XML are allowed to return only one row; therefore, to return more than one row of values in a SQL/XML subquery, they must be combined to form a single value. xmlagg() is an XML publishing function that produces a forest of elements by collecting the XML values that are returned from multiple rows and concatenating the values to make one value. Here is a query that uses the above subquery to create the XML output from the previous section:

The above query illustrates a very common pattern used to create XML hierarchies using SQL/XML.

Try DataDirect XQuery® Free!

Put the power, scalability, and performance of DataDirect XQuery® to work for you today! Our free trial lets you see for yourself how easy it is to build data integration applications that access relational, EDI, and other file formats as XML!

Download DataDirect XQuery® today!

Back to School with DataDirect XQuery®

Getting your mind around the possibilities of a data integration technology as promising as XQuery can be difficult, but our XML developers Webinars will help you understand the power and versatility of XQuery, and our favorite XQuery processor, DataDirect XQuery®.

Stay Informed!

XQuery is one of the hottest XML technologies being developed today. Stay informed with vital news about standards, tools, and trends by signing up for the DataDirect XQuery® newsletter.

New Case Study

Gevity produces sales proposals in real time using DataDirect XQuery®. See how Gevity uses DataDirect XQuery® to combine Web service data from SalesForce.com with relational data in Oracle in a pricing engine for HR management.

New Features in DataDirect XQuery®

DataDirect XQuery® is now released!

DataDirect XQuery® provides full update support for relational data, easy integration for Web Services, additional enhancements for performance and scalability and more!

Download now!

Where is XQuery Heading

We've collected numerous reports and surveys to help you understand the lay of the XQuery land and how DataDirect XQuery® can help you launch your data integration applications to new heights.

From XML industry observers to surveys of your peers, see why DataDirect XQuery® is right for you. Or better yet, try DataDirect XQuery® today for free!

DataDirect XQuery® and Document Projection

Querying large — over one Gig! — XML documents is no problem for DataDirect XQuery®, which uses document projection and data streaming technologies to efficiently query XML. Read about it, and then try DataDirect XQuery® for free and see for yourself.

DataDirect XQuery FAQ

This informative DataDirect XQuery® FAQ answers frequently-asked questions about DataDirect XQuery®, including questions about performance, scalability, use-cases, resources, and more.

If you're more of a hands-on learner, then download a free copy and start exploring DataDirect XQuery® today!

Online Video Tutorials!

Our easy-to-follow online video tutorials are a great way to get acquainted with the many features of DataDirect XQuery®.

And if you like what you see, download a free copy today and try DataDirect XQuery® for yourself!