mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-27 14:28:56 +00:00

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@334662 c90b9560-bf6c-de11-be94-00142212c4b1
309 lines
9.5 KiB
XML
309 lines
9.5 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<refentry xml:id="function.yaz-record" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
<refnamediv>
|
|
<refname>yaz_record</refname>
|
|
<refpurpose>Returns a record</refpurpose>
|
|
</refnamediv>
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>string</type><methodname>yaz_record</methodname>
|
|
<methodparam><type>resource</type><parameter>id</parameter></methodparam>
|
|
<methodparam><type>int</type><parameter>pos</parameter></methodparam>
|
|
<methodparam><type>string</type><parameter>type</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
The <function>yaz_record</function> function inspects a record in the
|
|
current result set at the position specified by parameter
|
|
<parameter>pos</parameter>.
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>id</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
The connection resource returned by <function>yaz_connect</function>.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>pos</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
The record position. Records positions in a result set are numbered 1,
|
|
2, ... $hits where $hits is the count returned by <function>yaz_hits</function>.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>type</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
The <parameter>type</parameter> specifies the form of the
|
|
returned record.
|
|
</para>
|
|
<note>
|
|
<para>
|
|
It is the application which is responsible for actually
|
|
ensuring that the records are returned from the Z39.50/SRW server
|
|
in the proper format. The type given only specifies a conversion
|
|
to take place on the client side (in PHP/YAZ).
|
|
</para>
|
|
</note>
|
|
<para>
|
|
Besides conversion of the transfer record to a string/array, PHP/YAZ
|
|
it is also possible to perform a character set conversion of the
|
|
record. Especially for USMARC/MARC21 that is recommended since
|
|
these are typically returned in the character set MARC-8 that is
|
|
not supported by browsers, etc. To specify a conversion, add
|
|
<literal>; charset=</literal><replaceable>from</replaceable><literal>,
|
|
</literal><replaceable>to</replaceable> where
|
|
<replaceable>from</replaceable> is the original character set
|
|
of the record and <replaceable>to</replaceable> is the resulting character
|
|
set (as seen by PHP).
|
|
</para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><literal>string</literal></term>
|
|
<listitem>
|
|
<para>
|
|
The record is returned as a string for simple display.
|
|
In this mode, all MARC records are converted to a line-by-line format
|
|
since ISO2709 is hardly readable.
|
|
XML records and SUTRS are returned in their original format.
|
|
GRS-1 are returned in a (ugly) line-by-line format.
|
|
</para>
|
|
<para>
|
|
This format is suitable if records are to be displayed in a quick
|
|
way - for debugging - or because it is not feasible to perform
|
|
proper display.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><literal>xml</literal></term>
|
|
<listitem>
|
|
<para>
|
|
The record is returned as an XML string if possible.
|
|
In this mode, all MARC records are converted to
|
|
<link xlink:href="&url.yaz-marcxml;">MARCXML</link>.
|
|
XML records and SUTRS are returned in their original format.
|
|
GRS-1 is not supported.
|
|
</para>
|
|
<para>
|
|
This format is similar to <parameter>string</parameter> except that
|
|
MARC records are converted to MARCXML
|
|
</para>
|
|
<para>
|
|
This format is suitable if records are processed by an XML parser
|
|
or XSLT processor afterwards.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><literal>raw</literal></term>
|
|
<listitem>
|
|
<para>
|
|
The record is returned as a string in its original form.
|
|
This type is suitable for MARC, XML and SUTRS. It does not
|
|
work for GRS-1.
|
|
</para>
|
|
<para>
|
|
MARC records are returned as a ISO2709 string. XML and SUTRS are
|
|
returned as strings.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><literal>syntax</literal></term>
|
|
<listitem>
|
|
<para>
|
|
The syntax of the record is returned as a string, i.e.
|
|
<literal>USmarc</literal>, <literal>GRS-1</literal>,
|
|
<literal>XML</literal>, etc.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><literal>database</literal></term>
|
|
<listitem>
|
|
<para>
|
|
The name of database associated with record at the position
|
|
is returned as a string.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><literal>array</literal></term>
|
|
<listitem>
|
|
<para>
|
|
The record is returned as an array that reflects the GRS-1
|
|
structure. This type is suitable for MARC and GRS-1. XML, SUTRS
|
|
are not supported and if the actual record is XML or SUTRS an
|
|
empty string will be returned.
|
|
</para>
|
|
<para>
|
|
The array returned consists of a list corresponding to
|
|
each leaf/internal node of GRS-1. Each list item consists
|
|
a sub list with first element <emphasis>path</emphasis> and
|
|
<emphasis>data</emphasis> (if data is available).
|
|
</para>
|
|
<para>
|
|
The path which is a string holds a list of each tree component (of
|
|
the structured GRS-1 record) from root to leaf. Each component is
|
|
a tag type, tag value pair of the form
|
|
<literal>(</literal><replaceable>type</replaceable><literal>,</literal>
|
|
<replaceable>value</replaceable>
|
|
</para>
|
|
<para>
|
|
String tags normally has a corresponding tag type 3.
|
|
MARC can also be returned as an array (they are converted to
|
|
GRS-1 internally).
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Returns the record at position <parameter>pos</parameter> or an empty
|
|
string if no record exists at the given position.
|
|
</para>
|
|
<para>
|
|
If no database record exists at the given position an empty string is
|
|
returned.
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<example>
|
|
<title>Array for GRS-1 record</title>
|
|
<para>
|
|
Consider this GRS-1 record:
|
|
<screen>
|
|
<![CDATA[
|
|
(4,52)Robert M. Pirsig
|
|
(4,70)
|
|
(4,90)
|
|
(2,7)Transworld Publishers, ltd.
|
|
]]>
|
|
</screen>
|
|
This record has two nodes at root level. First element at root level is
|
|
(4,52) [tag type 4, tag value 52], and has data <literal>Robert M.
|
|
Pirsig</literal>. Second element at root level (4,70) has a subtree with
|
|
a single element (4,90). (4,90) has yet another sub tree (2,7) with data
|
|
<literal>Transworld Publishers, ltd.</literal>.
|
|
</para>
|
|
<para>
|
|
If this record is present at position $p, then
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$ar = yaz_record($id, $p, "array");
|
|
print_r($ar);
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
will output:
|
|
<screen>
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[0] => Array
|
|
(
|
|
[0] => (4,52)
|
|
[1] => Robert M. Pirsig
|
|
)
|
|
[1] => Array
|
|
(
|
|
[0] => (4,70)
|
|
)
|
|
[2] => Array
|
|
(
|
|
[0] => (4,70)(4,90)
|
|
)
|
|
[3] => Array
|
|
(
|
|
[0] => (4,70)(4,90)(2,7)
|
|
[1] => Transworld Publishers, ltd.
|
|
)
|
|
)
|
|
]]>
|
|
</screen>
|
|
</para>
|
|
</example>
|
|
<example>
|
|
<title>Working with MARCXML</title>
|
|
<para>
|
|
The following PHP snippet returns a MARC21/USMARC record as MARCXML.
|
|
The original record is returned in marc-8 (unknown to most XML parsers),
|
|
so we convert it to UTF-8 (which all XML parsers must support).
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$rec = yaz_record($id, $p, "xml; charset=marc-8,utf-8");
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</para>
|
|
<para>
|
|
The record <literal>$rec</literal> can be processed with the
|
|
Sablotron XSLT processor as follows:
|
|
</para>
|
|
<para>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$xslfile = 'display.xsl';
|
|
$processor = xslt_create();
|
|
$parms = array('/_xml' => $rec);
|
|
$res = xslt_process($processor, 'arg:/_xml', $xslfile, NULL, $parms);
|
|
xslt_free($processor);
|
|
$res = preg_replace("'</?html[^>]*>'", '', $res);
|
|
echo $res;
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</para>
|
|
<para>
|
|
For PHP 5 the <link linkend="book.xsl">XSL</link> extension must be used
|
|
instead of Sablotron XSLT.
|
|
</para>
|
|
</example>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|