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
Phrases
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 & 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

xml_cut

creates a new XML document which contains a copy of data pointed by given XML tree- or XPER- entity
xml_cut (in source_entity any (XML entity));
Description

In some special cases, some part of XML document, being pointed by a XML entity, should be copied into a new separate document with new entity pointing to the top-level element or the root of this document. One reason for doing this is optimization of XPER processing (see xper_cut). Another way to use this functionality is passing of some XML entity to a function, when function uses XPath operations with references to the "document's root".

A sample of hidden bug

create procedure get_C (inout b any)
{
  return cast (xpath_eval('//C', b) as varchar);
}

create procedure hidden_bug_1()
{
  declare abc any;	-- some XML document
  declare b_list any;	-- a vector of all B elements of the doc
  declare c1 varchar;	-- a name of first variable
  declare c2 varchar;	-- a title of second variable
  abc := xtree_doc ('<A><B id="1"><C>One</C></B><B id="2"><C>Two</C></B></A>');
  b_list := xpath_eval ('//B', abc, 0);
  -- now b_list is a vector of two items, '<B id="1"><C>One</C></B>' and '<B id="2"><C>Two</C></B>'.
  c1 := get_C ( aref (b_list, 0));
  -- looks fine, c1 is '<C>One</C>'
  c2 := get_C ( aref (b_list, 1));
  -- looks strange fine, c2 is '<C>One</C>',
  -- while the expected value is '<C>Two</C>'.
}
      

The origin of the bug is '//C' path in get_C(), which returns not the "C element inside given b element", but "C element inside the document where given b element is located", thus get_C returns the first C element in the whole document with any of two B elements given.

There are two ways to fix this bug. It is better to correct get_C():

create procedure get_C (inout b any)
{
  return cast (xpath_eval('./C', b) as varchar);
}
      

If you cannot patch get_C() for some reason, xml_cut will help, but it will waste both memory and CPU time for copying a branch of XML tree:

create procedure hidden_bug_1()
{
...
  c1 := get_C ( xml_cut (aref (b_list, 0)));
...
}
      

The current node of the resulting entity is the node that is a copy of the current node of the source entity. In common, the top-level node of the copied subtree becomes the current node of the result. There are two special cases, however. If the source entity is an attribute entity, then the result is also an attribute entity and the attribute name remains the same. If the source entity points to the root of the document, the resulting entity also points to the root of the copied document, not to its top-level node.

With XPER entity given, xml_cut() works exactly as xper_cut().

Parameters
source_xper – XML Entity to be converted into new document
See Also

xper_cut