Available in versions: Dev (3.22)
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.
Importing XML
Supported by ✅ Open Source Edition ✅ Express Edition ✅ Professional Edition ✅ Enterprise Edition
The below XML data represents two book records that may have been exported previously, by jOOQ's exporting functionality:
<result xmlns="http://www.jooq.org/xsd/jooq-export-3.10.0.xsd">
<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>
This is the same format that is read by DSLContext.fetchFromXML(). The following examples show how to map source data and target table.
// Specify fields from the target table to be matched with fields from the source XML by position.
// The position of a source field is the position of its <field/> element in the <fields/> element.
create.loadInto(BOOK)
.loadXML(inputstream, encoding)
.fields(BOOK.ID, BOOK.AUTHOR_ID, BOOK.TITLE)
.execute();
// Use "null" field placeholders to ignore source columns by position.
create.loadInto(BOOK)
.loadXML(inputstream, encoding)
.fields(BOOK.ID, null, BOOK.TITLE)
.execute();
// Match target fields with source fields by "corresponding" name.
// This uses the names of the <field/> elements in the XML content, as exported by jOOQ
create.loadInto(BOOK)
.loadXML(inputstream, encoding)
.fieldsCorresponding()
.execute();
Apart from File, InputStream, Reader, String, and org.jooq.Source content, XML data can also be loaded from an org.xml.sax.InputSource. If the source data type information is present in the type attribute of the <field/> elements, it is used to read the values. Otherwise, the values are read as strings and converted to the target table's column types.
Like the JSON format, the XML format is currently read into memory entirely before the data is loaded. No other, XML-specific options are currently available.
Feedback
Do you have any feedback about this page? We'd love to hear it!