www.openlinksw.com
docs.openlinksw.com

Book Home

Contents
Preface

Virtuoso Functions Guide

Administration
Aggregate Functions
Array Manipulation
BPEL APIs
Backup
Compression
Cursor
Date & Time Manipulation
Debug
Dictionary Manipulation
Encoding & Decoding
File Manipulation
Free Text
Hashing / Cryptographic
LDAP
Locale
Mail
Miscellaneous
Number
RDF data
Remote SQL Data Source
Replication
SOAP
SQL
String
Transaction
Type Mapping
UDDI
User Defined Types & The CLR
Virtuoso Java PL API
Virtuoso Server Extension Interface (VSEI)
Web Server & Internet
XML
xmlagg
xmlattributes
xmladdattribute
xmlappendchildren
xmlconcat
xmlelement
xmlforest
xmlinsertafter
xmlinsertbefore
xmlreplace
xmltype.xmltype
xmltype.createnonsch...
xmltype.createschema...
xmltype.createxml
xmltype.existsnode
xmltype.extract
xmltype.getclobval
xmltype.getnamespace
xmltype.getnumval
xmltype.getrooteleme...
xmltype.getschemaurl
xmltype.getstringval
xmltype.isfragment
xmltype.isschemabase...
xmltype.isschemavali...
xmltype.isschemavali...
xmltype.schemavalida...
xmltype.setschemaval...
xmltype.toobject
xmltype.transform
xmlupdate
xper navigation
createxml
isentity
serialize_to_utf8_xm...
tidy_html
tidy_list_errors
updatexml
xml_add_system_path
xml_auto
xml_auto_dtd
xml_auto_schema
xml_create_tables_fr...
xml_cut
xml_doc_output_optio...
xml_get_system_paths
xml_load_mapping_sch...
xml_load_schema_decl
xml_namespace_scope
xml_persistent
xml_set_ns_decl
xml_template
xml_tree
xml_tree_doc
xml_tree_doc_media_t...
xml_uri_get
xml_validate_dtd
xml_validate_schema
xml_view_dtd
xml_view_schema
xmlsql_update
xpath_eval
xper_cut
xper_doc
xper_locate_words
xpf_extension
xpf_extension_remove
xquery_eval
xslt
xslt_format_number
xslt_sheet
xslt_stale
xte_head
xte_node
xte_node_from_nodebl...
xte_nodebld_acc
xte_nodebld_final
xte_nodebld_init
xtree_doc
XPATH & XQUERY

Functions Index

XMLType.getRootElement

Returns top-level element of the given instance (NULL for fragment)
XMLType.getRootElement
Description

If the given instance is well-formed then this function will return the top-level element of the document that is stored within the instance. If the given instance is a fragment then NULL will be returned because there may be no top-level elements or too many of them.

Note that in spite of this functions name this function actually returns the a top-level node rather than not a root node. According to the W3C XPATH standards, the root element is an implicit node whose children are top-level elements, comments, processing instructions and maybe text nodes. E.g. if a correct HTML document is started by tag <HTML> and ended by corresponding </HTML> tag then the only top-level node is the "HTML" element node and this node is a single child of the root node.

If the given instance is well-formed then the function returns a top-level element of the document that is stored in the instance. If the given instance is fragment then NULL is returned, because there may be no top-level elements or too many of them.

If the given instance is schema-based then the returned instance is based on the same schema.

Return Types

The function returns an XMLType instance.

Examples
A table with an XMLType column

First select statement lists well-formed documents; second one lists the only fragment in the table.

create table TEST_XMLS  (I integer primary key, XMLVAL XMLType);
insert into TEST_XMLS  values (1, XMLType('<emp><empno>221</empno><ename>John</ename></emp>'));
insert into TEST_XMLS  values (2, XMLType('<po><pono>331</pono><poname>PO_1</poname></po>'));
insert into TEST_XMLS  values (3, XMLType('<oil-rig id="14a" water="0.413"/><oil-rig id="14b" water="0.402"/>'));

select e.I, e.XMLVAL.getRootElement().getClobVal()
  from TEST_XMLS as e
  where e.XMLVAL.getRootElement() is not null
I                 callret
INTEGER NOT NULL  NVARCHAR
_______________________________________________________________________________

1                 <emp><empno>221</empno><ename>John</ename></emp>
2                 <po><pono>331</pono><poname>PO_1</poname></po>

2 Rows. -- 00000 msec.

select e.I, e.XMLVAL.getClobVal()
  from TEST_XMLS as e
  where e.XMLVAL.getRootElement() is null
I                 callret
INTEGER NOT NULL  NVARCHAR
_______________________________________________________________________________

3                 <oil-rig id="14a" water="0.413" /><oil-rig id="14b" water="0.402" />

1 Rows. -- 00000 msec.

See Also

XMLType.isFragment()