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_namespace_scope

Returns a vector of all namespace declarations in all ancestors of the given XML entity.
vector xml_namespace_scope (in ent XML Entity, in use_default_ns integer);
Description

The function returns a vector of even length that consists of all declared namespace prefixes and namespace URIs from the ent and all its ancestors. This information is needed for processing XML documents that contains a mix of data and XPath expressions, such as BPEL documents.

Parameters
ent – The entity to process.
use_default_ns – Flags if the resulting array should contain declarations of default namespace. If it is zero then only declarations of namespace prefixes are listed; if non-zero then all declarations are listed.
Return Types

The function returns a vector of even length that contains narrow strings in UTF-8 encoding.

Examples
Adding namespace declarations to the XPath expression

The function gets an entity whose string-value is an XPATH expression and returns the text of expression with all namespace declarations that are in scope. The resulting expression is context-independent. This is useful for BPEL-like applications and for extracting XPATH expressions from XML Schema documents.

create procedure xpath_add_namespace_scope (in ent any, in use_default_ns integer)
{
  declare _expn varchar;
  declare _ses any;
  declare _scope any;
  declare _ctr any;
  _expn := charset_recode (xpath_eval ('string(.)', ent), '_WIDE_', 'UTF-8');
  _scope := xml_namespace_scope (ent, use_default_ns);
  _ctr := length (_scope);
  if (_ctr = 0)
    return _expn;
  _ses := string_output ();
  http ('[', _ses);
  while (_ctr > 0)
    {
      if (_scope[_ctr-2] = '')
        http (sprintf (' xmlns="%s"', _scope[_ctr-1]), _ses);
      else
        http (sprintf (' xmlns:%s="%s"', _scope[_ctr-2], _scope[_ctr-1]), _ses);
      _ctr := _ctr - 2;
    }
  http (' ] ', _ses);
  http (_expn, _ses);
  return string_output_string (_ses);
}

select xpath_add_namespace_scope (
  xquery_eval (
'declare namespace xsd="http://www.w3.org/2001/XMLSchema";
//xsd:keyref[@name="ISBNnumber"]/xsd:field/@xpath',
    xtree_doc (
'<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        targetNamespace="http://www.publishing.org"
        xmlns="http://www.publishing.org">
  <xsd:element name="Book"  minOccurs="1" maxOccurs="unbounded">
    <xsd:keyref name="ISBNnumber" refer="BookDB_ISBN">
      <xsd:selector xpath="."/>
      <xsd:field xpath="ISBN"/>
    </xsd:keyref>
  </xsd:element>
  <!-- The rest of the XML Schema file is skipped -->
</xsd:schema>')),
  1 );

callret
VARCHAR
_______________________________________________________________________________

[ xmlns="http://www.publishing.org" xmlns:xsd="http://www.w3.org/2001/XMLSchema" ] ISBN

See Also

xpath_eval