Chapter 24 · JSON, XML, Spatial, Graph, and Converged Data Capabilities

XMLType/XML DB Awareness, Legacy XML Workloads, and Migration Boundaries

Maintain legacy XMLType/XML DB workloads with modern SQL/XML and 26ai Transportable Binary XML awareness, then decide migration to relational or JSON forms from schema, namespace, ordering, signature and client-contract evidence.

Advanced120–140 minutesXMLType + XMLTABLE/XMLQUERY migration lab26ai TBX default when COMPATIBLE ≥ 23.0Legacy XML maintenance literacyLast reviewed: August 2026

Learning outcomes

ServiceHub acquires a maintenance system whose external partners exchange signed, namespace-qualified XML documents validated against long-lived contracts. “Convert it all to JSON” sounds modern but can silently break namespaces, element order, XML Schema validation, digital-signature/canonicalization behavior and partner APIs. Oracle XML DB and SQL data type XMLType remain a supported maintenance surface; the engineering question is which XML semantics are contractual and which data should be projected into relational/JSON forms for easier new development.

01

Create/query XMLType using current SQL/XML functions XMLExists, XMLQuery, XMLCast and XMLTable.

02

Explain Oracle XML DB and 26ai Transportable Binary XML default storage at COMPATIBLE >= 23.0.

03

Recognize deprecated extract/extractValue-era code without extending it into new designs.

04

Demonstrate malformed XML and a migration that loses XML semantics, then build a staged relational/JSON projection instead.

05

Define migration acceptance around namespaces, schema/ordering/signatures/round-trip fidelity and external client contracts.

Generation-time baseline, licensing, compatibility, and topology boundary

Mandatory examples target Oracle AI Database Free 26ai and were reviewed against RU 23.26.3, SQL Developer 26.2, and SQLcl 26.2.1.222.1617. Free is capped at 2 foreground CPU cores, 2 GB database RAM, 12 GB user data, and one installation per logical environment; Oracle Free receives no Release Update patches or Oracle Support SRs. The course CDB/PDB baseline remains FREE/FREEPDB1 and the schema/domain remains SERVICEHUB_OWNER/ServiceHub. Current 26ai licensing lists Oracle Spatial and Graph plus Property Graph and RDF Graph Technologies (RDF/OWL) as available across all listed offerings, including Free; parallel spatial index builds are not available in Free, and partitioned spatial indexes have offering-specific Partitioning requirements. JSON/XML examples require no management pack. Native SQL data type JSON requires COMPATIBLE >= 20. XMLType created in 26ai defaults to Transportable Binary XML when COMPATIBLE >= 23.0. JSON Relational Duality Views and SQL property-graph dictionary views are 26ai capabilities. No mandatory lab changes COMPATIBLE, enables RAC/Data Guard/GoldenGate, or installs external Graph Server/Client.

1. XMLType keeps XML as XML

XMLType is Oracle's SQL type for XML documents/fragments. Oracle XML DB supplies storage/query/schema/repository capabilities around it. Starting in 26ai, when COMPATIBLE >= 23.0.0.0, newly created XMLType storage defaults to Transportable Binary XML (TBX), designed for cross-platform transport and efficient XML processing.

sql · check the compatibility boundary
SELECT name,valueFROM v$parameterWHERE name='compatible';

2. Build a namespaced legacy work-order envelope

sql · setup
BEGIN  EXECUTE IMMEDIATE 'DROP TABLE sh24_xml_messages PURGE';EXCEPTION WHEN OTHERS THEN  IF SQLCODE != -942 THEN RAISE; END IF;END;/CREATE TABLE sh24_xml_messages (  message_id NUMBER PRIMARY KEY,  received_at TIMESTAMP DEFAULT SYSTIMESTAMP NOT NULL,  payload XMLTYPE NOT NULL);INSERT INTO sh24_xml_messages(message_id,payload)VALUES(  1,  XMLTYPE(q'~<wo:WorkOrder xmlns:wo="urn:servicehub:workorder:v1">    <wo:Id>7001</wo:Id>    <wo:Status>OPEN</wo:Status>    <wo:Priority>2</wo:Priority>    <wo:Customer>      <wo:Name>Ada Services</wo:Name>    </wo:Customer>  </wo:WorkOrder>~'));COMMIT;

3. XMLExists filters; XMLQuery returns XML content

sql · namespace-aware XMLExists
SELECT message_idFROM sh24_xml_messages mWHERE XMLEXISTS(  'declare namespace wo="urn:servicehub:workorder:v1";   /wo:WorkOrder[wo:Status="OPEN"]'  PASSING m.payload);-- Expected: message_id 1.
sql · XMLQuery returns XMLType content
SELECT XMLSERIALIZE(         CONTENT XMLQUERY(           'declare namespace wo="urn:servicehub:workorder:v1";            /wo:WorkOrder/wo:Customer'           PASSING payload           RETURNING CONTENT         )         AS CLOB       ) AS customer_xmlFROM sh24_xml_messagesWHERE message_id=1;

4. XMLTable turns selected XML structure into relational columns

sql · relational projection
SELECT  m.message_id,  x.work_order_id,  x.status_code,  x.priority_code,  x.customer_nameFROM sh24_xml_messages m,     XMLTABLE(       XMLNAMESPACES(         'urn:servicehub:workorder:v1' AS "wo"       ),       '/wo:WorkOrder'       PASSING m.payload       COLUMNS         work_order_id NUMBER        PATH 'wo:Id',         status_code   VARCHAR2(12)  PATH 'wo:Status',         priority_code NUMBER        PATH 'wo:Priority',         customer_name VARCHAR2(100) PATH 'wo:Customer/wo:Name'     ) x;

This projection does not mutate or discard the XML. It lets ordinary SQL consume selected values while the original partner payload remains available for audit/replay/round-trip requirements.

5. Current SQL/XML replaces deprecated extract/extractValue patterns

Legacy code may contain Oracle SQL functions extract and extractValue, deprecated since 11g Release 2. Maintain them carefully while planning migration to standards-based XMLQuery, XMLTable, XMLExists and XMLCast. Do not introduce new application code on the deprecated functions.

6. Deliberately malformed XML fails at parse time

sql · bad document
INSERT INTO sh24_xml_messages(message_id,payload)VALUES(  2,  XMLTYPE('<WorkOrder><Id>7002</Id></WorkOrderBROKEN>'));-- Expected XML parser failure, typically including ORA-31011-- plus LPX/XML parsing diagnostics.

The safe repair is not to store unvalidated arbitrary text in XMLType. Fix or quarantine the producer payload, preserve the raw envelope separately only if incident/audit requirements demand it, and accept into XMLType once it is well-formed.

7. Wrong migration: regex/string-replace XML into JSON

Text replacement such as changing <wo:Status> into "status": ignores namespace URIs, entity escaping, attributes, mixed content, element ordering, repeated elements and schema typing. It can also invalidate XML signatures. The migration can produce syntactically valid JSON whose business meaning is wrong.

8. Safer staged migration boundary

sql · extract the contract fields into a relational staging table
CREATE TABLE sh24_xml_projection (  message_id NUMBER PRIMARY KEY,  work_order_id NUMBER NOT NULL,  status_code VARCHAR2(12) NOT NULL,  priority_code NUMBER,  customer_name VARCHAR2(100),  source_xml XMLTYPE NOT NULL);INSERT INTO sh24_xml_projectionSELECT  m.message_id,  x.work_order_id,  x.status_code,  x.priority_code,  x.customer_name,  m.payloadFROM sh24_xml_messages m,     XMLTABLE(       XMLNAMESPACES(         'urn:servicehub:workorder:v1' AS "wo"       ),       '/wo:WorkOrder'       PASSING m.payload       COLUMNS         work_order_id NUMBER        PATH 'wo:Id',         status_code   VARCHAR2(12)  PATH 'wo:Status',         priority_code NUMBER        PATH 'wo:Priority',         customer_name VARCHAR2(100) PATH 'wo:Customer/wo:Name'     ) x;COMMIT;
sql · generate a new JSON API from the relational projection
SELECT JSON_OBJECT(         'workOrderId' VALUE work_order_id,         'status'      VALUE status_code,         'priority'    VALUE priority_code,         'customer'    VALUE customer_name         RETURNING JSON       ) AS json_api_documentFROM sh24_xml_projection;

The original XML remains available while the new application can consume relational/JSON projections. Once external contracts and round-trip requirements are retired, the XML retention policy can be reconsidered deliberately.

9. XML migration acceptance tests

Question Why it matters
Namespace URI preserved? Prefixes can change; namespace identity must not.
Ordering/mixed content significant? Relational/JSON models may not preserve XML document semantics.
XSD typed/defaulted values? Schema validation can add/limit semantics absent from raw strings.
Signed/canonicalized document? Reformatting can invalidate signatures.
Repeated elements/attributes? Must map explicitly to arrays/tables/properties.
Partner API still XML? Internal migration cannot unilaterally break external protocol.

10. Driver/tool boundary

SQL/SQLcl/SQL Developer can operate XMLType directly. Some XMLType-specific APIs are not fully supported by thin JDBC paths; Oracle XML DB documents OCI/thick-driver differences for certain XMLType functions. New application code should prefer portable SQL/XML result shapes unless an XML-specific client API is actually required.

11. Cleanup

sql · cleanup
DROP TABLE sh24_xml_projection PURGE;DROP TABLE sh24_xml_messages PURGE;

12. Production judgment

Keep XML when XML-specific semantics or external contracts are real requirements. Use XMLTable/XMLExists/XMLQuery/XMLCast for maintainable current SQL/XML. Migrate only the portions whose document semantics can be mapped and verified; preserving an authoritative source XML during transition is often cheaper than a risky flag-day conversion.

In 26ai with COMPATIBLE >= 23.0, XMLType defaults to Transportable Binary XML. The mandatory lab needs no pack, extra-cost option, restart or configuration change. XML DB remains available, but new designs should earn XML complexity from a real contract rather than historical inertia. Lesson 3 shifts from hierarchical documents to another specialized type whose semantics cannot safely be reduced to generic numeric columns: geospatial data.

Check your understanding

  1. What does XMLTable do?
  2. Why are namespaces part of the data contract?
  3. What changed for default XMLType storage in 26ai at COMPATIBLE >= 23.0?
  4. Why is regex/string replacement an unsafe XML-to-JSON migration method?
  5. When is retaining the original XML during migration valuable?
Review the answers

It projects XML nodes into relational rows/columns using XQuery/XPath semantics.

Namespace URIs identify element vocabularies; matching only textual prefixes/names can select the wrong or no nodes.

New XMLType storage defaults to Transportable Binary XML.

It ignores XML namespaces, escaping, attributes, repeated/mixed content, schema typing and signature/canonicalization semantics.

When audit/replay/round-trip/external partner contracts still depend on the exact XML source while new relational/JSON projections are validated.

Authoritative references

Keep knowledge open

Help the academy stay free and grow.

If these tutorials save you time, a small donation supports new lessons, technical review, diagrams, examples, and long-term maintenance.

ETHEthereum / ERC-20 only
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0

Send only Ethereum or ERC-20 compatible assets to this address.