<<<<<<< HEAD xmltext | H2 | SQLDoc
Skip to main content

xmltext

1. XMLTEXT Function​

======= xmltext | H2 Function | SQLDoc

xmltext

1. XMLTEXT Function​

>>>>>>> 9d19b1c8cb744c8e86d5c15b74d8b5f719ad62be

The XMLTEXT function in H2 database is used to extract the text content from an XML element.

2. Syntax​

The syntax for the XMLTEXT function in H2 database is as follows:

XMLTEXT(xml)

Arguments​

  • xml: The XML element from which the text content needs to be extracted. It should be a valid XML string.

Return​

  • The XMLTEXT function returns the text content of the given XML element.

3. Notes​

  • The XMLTEXT function in H2 database expects the input to be a valid XML string. If the input is not a valid XML, the function may throw an error or return unexpected results.
  • If the given XML element contains nested elements, the XMLTEXT function will return the concatenated text content of all the nested elements.
  • Remember to use the correct syntax and provide valid XML input while using the XMLTEXT function to avoid errors.

4. Examples​

Here are a few examples demonstrating the usage of the XMLTEXT function in H2 database:

Example 1 - Extracting text content from a simple XML element:​

SELECT XMLTEXT('<name>John Doe</name>') AS text_content;

Output:

text_content
-------------
John Doe

Example 2 - Extracting text content from a nested XML element:​

SELECT XMLTEXT('<person><name>John Doe</name><age>30</age></person>') AS text_content;

Output:

text_content
-------------
John Doe30
  • xmlnode - Extract XML node from an XML document
  • XMLEXISTS - Check if an XML element exists in an XML document