1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
-
- This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
- project.
-
- Copyright (C) 1998-2018 OpenLink Software
-
- This project is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by the
- Free Software Foundation; only version 2 of the License, dated June 1991.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-
-->
<refentry id="fn_xml_namespace_scope">
<refmeta>
<refentrytitle>xml_namespace_scope</refentrytitle>
<refmiscinfo>xml</refmiscinfo>
</refmeta>
<refnamediv>
<refname>xml_namespace_scope</refname>
<refpurpose>Returns a vector of all namespace declarations in all ancestors of the given XML entity.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis id="fsyn_xml_namespace_scope">
<funcprototype id="fproto_xml_namespace_scope">
<funcdef>vector <function>xml_namespace_scope</function></funcdef>
<paramdef>in <parameter>ent</parameter> XML Entity</paramdef>
<paramdef>in <parameter>use_default_ns</parameter> integer</paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1 id="desc_xml_namespace_scope">
<title>Description</title>
<para>The function returns a vector of even length that consists of all declared namespace prefixes and namespace URIs
from the <code>ent</code> 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.</para>
</refsect1>
<refsect1 id="params_xml_namespace_scope">
<title>Parameters</title>
<refsect2><title>ent</title>
<para>The entity to process.</para>
</refsect2>
<refsect2><title>use_default_ns</title>
<para>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.</para>
</refsect2>
</refsect1>
<refsect1 id="ret_xml_namespace_scope"><title>Return Types</title>
<para>The function returns a vector of even length that contains narrow strings in UTF-8 encoding.</para>
</refsect1>
<!--
<refsect1 id="errors_xml_namespace_scope">
<title>Errors</title>
<para>This function can generate the following errors:</para>
<errorcode></errorcode>
</refsect1>
-->
<refsect1 id="examples_xml_namespace_scope">
<title>Examples</title>
<example id="ex_xml_namespace_scope"><title>Adding namespace declarations to the XPath expression</title>
<para>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.</para>
<screen><![CDATA[
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
]]>
</screen>
</example>
</refsect1>
<refsect1 id="seealso_xml_namespace_scope">
<title>See Also</title>
<para><link linkend="fn_xpath_eval"><function>xpath_eval</function></link></para>
</refsect1>
</refentry>
|