New versions: Dev (3.15) | Latest (3.14) | 3.13 | 3.12 | 3.11 | 3.10 | 3.9 | 3.8 | Old versions: 3.7 | 3.6 | 3.5 | 3.4 | 3.3

Exporting XML

Applies to ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

// Fetch books and format them as XML
String xml = create.selectFrom(BOOK).fetch().formatXML();

The above query will result in an XML document looking like the following one:

<result xmlns="">
    <field schema="TEST" table="BOOK" name="ID" type="INTEGER"/>
    <field schema="TEST" table="BOOK" name="AUTHOR_ID" type="INTEGER"/>
    <field schema="TEST" table="BOOK" name="TITLE" type="VARCHAR"/>
      <value field="ID">1</value>
      <value field="AUTHOR_ID">1</value>
      <value field="TITLE">1984</value>
      <value field="ID">2</value>
      <value field="AUTHOR_ID">1</value>
      <value field="TITLE">Animal Farm</value>

The same result as an org.w3c.dom.Document can be obtained using the Result.intoXML() method:

// Fetch books and format them as XML
Document xml = create.selectFrom(BOOK).fetch().intoXML();

See the XSD schema definition here, for a formal definition of the XML export format:


Do you have any feedback about this page? We'd love to hear it!

The jOOQ Logo