Available in versions: Dev (3.22) | Latest (3.21) | 3.20 | 3.19 | 3.18 | 3.17 | 3.16 | 3.15 | 3.14 | 3.13 | 3.12

This documentation is for the unreleased development version of jOOQ. Click on the above version links to get this documentation for a supported version of jOOQ.

Reading XML

Supported by ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

DSLContext.fetchFromXML() is the inverse operation of exporting XML. It parses an XML string in the format produced by Result.formatXML() into a Result<Record>:

Result<Record> result = create.fetchFromXML(
    "<result>"
  + "  <fields>"
  + "    <field name=\"ID\" type=\"INTEGER\"/>"
  + "    <field name=\"AUTHOR_ID\" type=\"INTEGER\"/>"
  + "    <field name=\"TITLE\" type=\"VARCHAR\"/>"
  + "  </fields>"
  + "  <records>"
  + "    <record><value field=\"ID\">1</value><value field=\"AUTHOR_ID\">1</value><value field=\"TITLE\">1984</value></record>"
  + "    <record><value field=\"ID\">2</value><value field=\"AUTHOR_ID\">1</value><value field=\"TITLE\">Animal Farm</value></record>"
  + "  </records>"
  + "</result>"
);

If a <field/> element contains a type attribute, it is used to produce a field of the corresponding data type. Otherwise, the field is of type String. See the section about working with in-memory results to learn how to convert such results to other types.

If the goal is to load XML data directly into a database table, the Loader API's XML support may be a better fit.

References to this page

Feedback

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

The jOOQ Logo