# Inserting XML data into a table

**URL:** <https://forum.liquibase.org/t/inserting-xml-data-into-a-table/9774>\
**Category:** General Discussion\
**Created:** [September 23, 2024, 2:58pm UTC](https://forum.liquibase.org/t/inserting-xml-data-into-a-table/9774 "2024-09-23T14:58:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![derekgoodwin](https://avatars.discourse-cdn.com/v4/letter/d/da6949/32.png) [@derekgoodwin](https://forum.liquibase.org/u/derekgoodwin)\
**Post date:** [September 23, 2024, 2:58pm UTC](https://forum.liquibase.org/t/inserting-xml-data-into-a-table/9774/1 "2024-09-23T14:58:23Z")

</div>

I am trying to create a change set that inserts XML into a column in our database but liquibase doesn’t seem to like it. I’ve tried encoding \< and \> characters but no joy. Anyone else succeeded in doing this

---

<div class="post-metadata">

**Author:** ![daryldoak](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.liquibase.org/daryldoak/32/764_2.png) [@daryldoak](https://forum.liquibase.org/u/daryldoak)\
**Post date:** [September 23, 2024, 5:16pm UTC](https://forum.liquibase.org/t/inserting-xml-data-into-a-table/9774/2 "2024-09-23T17:16:30Z")

</div>

I’m going to assume you are using XML file format. You can use CDATA to insert XML into a table:

```auto
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
                        http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">

<changeSet id="insert_xml_into_test_department" author="BOB">
  <sql>
  <![CDATA[
    INSERT INTO test_department (employee_number, department_name)
    VALUES ('1', '<yourXML><data>Example</data></yourXML>');
  ]]>
  </sql>
  <rollback>
    DELETE FROM test_department
    WHERE employee_number = '1';
  </rollback>
</changeSet>
</databaseChangeLog>

```

In sql format:

```auto
--liquibase formatted sql
--changeset BOB:insert_xml_into_test_country stripComments:false

INSERT INTO test_country (country_number, country_name)
VALUES ('1', --county_number
        '<yourXML><data>Example</data></yourXML>') --country_name
;

/* liquibase rollback
DELETE FROM test_country where country_number = '1';
*/

```

In yaml format:

```auto
databaseChangeLog:
  - changeSet:
      id: insert_xml_into_test_city
      author: doaksec
      comment: Insert XML into the test_city table
      context: dev
      changes:
        - sql:
           sql: insert into test_city (id,city_name, mayor) values (1,'Portland','<yourXML><data>Example</data></yourXML>');
      rollback:
        - sql:
           sql: delete from test_city where id = 1;

```
