php-doc-en/reference/sdo_das_xml/reference.xml

671 lines
19 KiB
XML
Raw Normal View History

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.8 $ -->
<!-- Generated by xml_proto.php v2.2. Found in /scripts directory of phpdoc. -->
<reference id="ref.sdo-das-xml">
<title>SDO XML Data Access Service Functions</title>
<titleabbrev>SDO DAS XML</titleabbrev>
<partintro>
<section id="sdo-das-xml.intro">
&reftitle.intro;
<para>
<!-- This warns that the extension is experimental -->
&warn.experimental;
</para>
<para>
In order to use the XML Data Access Service for Service Data Objects,
you will need to understand some of the concepts behind SDO:
the data graph, the data object, XPath and property expressions,
and so on.
If you are not familiar with these ideas, you might want to look first at
<link linkend='ref.sdo'>the section on SDO</link>
.
</para>
<para>
The job of the XML DAS is to move data between the
application and an XML data source.
In order to do this it needs to be told the
XML schema the XML should follow.
This model information is used to ensure conformance
of XML being written out, and also to ensure that
modifications made to an SDO originating from XML
follow the model described by the XML schema.
</para>
<para>
The XML DAS currently supports reading/writing XML
to/from a file or an http URL (for example, to support RSS feeds).
</para>
</section>
<section id="sdo-das-xml.requirements">
&reftitle.required;
<para>
The SDO XML Data Access Service requires PHP 5.1 or higher.
It is packaged with the SDO extension and requires
SDO to have been installed.
See the
<link linkend="sdo.installation">SDO installation instructions</link>
for steps on how to do this.
</para>
</section>
<section id="sdo-das-xml.installation">
&reftitle.install;
<para>
The XML Data Access Service is packaged and installed as part of the
<link linkend='ref.sdo'>SDO extension.</link> Please Refer
<link linkend="sdo.installation">SDO installation instructions.</link>
</para>
</section>
<section id='sdo-das-xml.limitations'>
<title>Limitations</title>
<para>
The
<ulink url='&url.ibm.sdo;'>SDO 2.0 specification</ulink>
defines the mapping between XML types and SDO types.
With Java SDO, this mapping is implemented by the XMLHelper.
With SDO for PHP, this mapping is implemented by the
XML Data Access Services.
The XML DAS implements the mapping described in the
SDO 2.0 specification with the following restrictions:
</para>
<procedure id='sdo-das-xml.limitations.simpletypes'>
<title>XML Simple Types</title>
<step>
<para>
Simple Type with abstract="true"
- no PHP support for SDO abstract types.
</para>
</step>
<step>
<para>
Simple Type with sdoJava:instanceClass
- no PHP equivalent provided.
</para>
</step>
<step>
<para>
Simple Type with sdoJava:extendedInstanceClass
- no PHP equivalent provided.
</para>
</step>
<step>
<para>
Simple Type with list of itemType.
</para>
</step>
<step>
<para>
Simple Type with union.
</para>
</step>
</procedure>
<procedure id='sdo-das-xml.limitations.complextypes'>
<title>XML Complex Types</title>
<step>
<para>
Complex Type with abstract="true"
- no PHP support for SDO abstract types.
</para>
</step>
<step>
<para>
Complex Type with sdo:aliasName
- no PHP support for SDO Type aliases.
</para>
</step>
<step>
<para>
Complex Type with open content
- no PHP support for SDO open types.
</para>
</step>
<step>
<para>
Complex Type with open attribute
- no PHP support for SDO open types.
</para>
</step>
</procedure>
<procedure id='sdo-das-xml.limitations.attribute'>
<title>XSD Attribute</title>
<step>
<para>
Attribute with sdo:aliasName
- no PHP support for SDO property aliases.
</para>
</step>
<step>
<para>
Attribute with default value
- no PHP support for SDO property defaults.
</para>
</step>
<step>
<para>
Attribute with fixed value
- no PHP support for SDO read-only properties or default values.
</para>
</step>
<step>
<para>
Attribute reference.
</para>
</step>
<step>
<para>
Attribute with sdo:string
- no support for sdo:string="true".
</para>
</step>
<step>
<para>
Attribute referencing a DataObject with
sdo:propertyType - no support for sdo:propertyType="...".
</para>
</step>
<step>
<para>
Attribute with bi-directional property to a DataObject with
sdo:oppositeProperty and sdo:propertyType
- no PHP support for SDO opposite.
</para>
</step>
</procedure>
<procedure id='sdo-das-xml.limitations.elements'>
<title>XSD Elements</title>
<step>
<para>
Element with sdo:aliasName
- no PHP support for SDO property aliases.
</para>
</step>
<step>
<para>
Element reference.
</para>
</step>
<step>
<para>
Element with nillable.
</para>
</step>
<step>
<para>
Element with substitution group.
</para>
</step>
</procedure>
<procedure id='sdo-das-xml.limitations.elementsimpletype'>
<title>XSD Elements with Simple Type</title>
<step>
<para>
Element of SimpleType with default
- no PHP support for SDO defaults
</para>
</step>
<step>
<para>
Element of SimpleType with fixed value
- no PHP support for SDO read-only properties or default values.
</para>
</step>
<step>
<para>
Element of SimpleType with sdo:string
- no support for sdo:string="true".
</para>
</step>
<step>
<para>
Element referencing a DataObject with
sdo:propertyType - no support for sdo:propertyType="..."
</para>
</step>
<step>
<para>
Element with bi-directional reference to a DataObject with
sdo:oppositeProperty and sdo:propertyType
- no PHP support for SDO opposite.
</para>
</step>
</procedure>
</section>
<section id='sdo-das-xml.examples'>
&reftitle.examples;
<para>
The following examples are based on the
<link linkend="sdo.sample.sequence">letter example</link>
described in the
<link linkend="ref.sdo">SDO documentation</link>
.
The examples assume the XML Schema for the letter is contained in a file
<filename>letter.xsd</filename>
and the letter instance is in the file
<filename>letter.xml</filename>
.
</para>
<example>
<title>Working with the SDO_DAS_XML Class</title>
<para>
The following example shows how to create a SDO_DAS_XML Object and
use it to load an instance document.
The SDO_DAS_XML object can be created by passing the xsd file
to the SDO_DAS_XML::create method, which is a static method
of SDO_DAS_XML Class.
This schema file(XSD Document) can be either file available
on the local file system or it can be an URL.
Once we have created the SDO_DAS_XML Object,
we can use the same to load the instance document using
loadFromFile method.
loadFromString method can be used if want load xml instance document
which is available as string.
On successful loading of the instance document,
you will be returned with an object of type SDO_DAS_XML_Document.
Use the getRootDataObject method of SDO_DAS_XML_Document
class to get the root DataObject.
This example also tries to modify the properties of the root
DataObject and then write the changed contents back to file system.
</para>
<programlisting role="php" id="sdo-das-xml.examples.loadfromfile">
<![CDATA[
<?php
try {
$xmldas = SDO_DAS_XML::create("letter.xsd");
$xdoc = $xmldas->loadFromFile("letter.xml");
$do = $xdoc->getRootDataObject();
$do->date = "September 03, 2004";
$do->firstName = "Anantoju";
$do->lastName = "Madhu";
$xmldas->saveDocumentToFile($xdoc, "letter-out.xml");
} catch (SDO_TypeNotFoundException $e) {
print("Type is not defined in the xsd file");
} catch (SDO_DAS_XML_ParserException $e) {
print("Problem while parsing");
}
?>
]]>
</programlisting>
</example>
<example>
<title>Working with the SDO_DAS_XML Class</title>
<para>
The above example shown, how to use the SDO_DAS_XML object to load an
existing instance document and change the DataObject(property values)
and write the changes back to file system.
This example shows, how to create the DataObjects dynamically and
save them as a xml string.
Please note that this example uses a company schema((
<link linkend="sdo.examples">company.xsd</link>
)) as defined in SDO samples section.
</para>
<programlisting role="php" id="sdo-das-xml.examples.createDataObject">
<![CDATA[
<?php
$xmldas = SDO_DAS_XML::create("company.xsd");
$do = $xmldas->createDataObject("companyNS", "CompanyType");
$do->name = "Acme Inc";
$dept1 = $do->createDataObject("departments");
$dept1->name = "sales";
$emp1 = $dept1->createDataObject("employees");
$emp1->name = "Fred";
$emp1->manager = FALSE;
$dept2 = $do->createDataObject("departments");
$emp2 = $dept2->createDataObject("employees");
$emp2->name = "Neil";
$emp2->manager = TRUE;
print($xmldas->saveDataObjectToString($do, "companyNS", "CompanyType"));
var_dump($do);
?>
]]>
</programlisting>
</example>
<example>
<title>Working with the SDO_DAS_XML Class</title>
<para>
This example shows you how to create the DataObject and use
the Sequence API (
<link linkend="sdo.sample.sequence">
For more information on Sequence API
</link>
) to construct a letter containing unstructured text.
</para>
<programlisting role="php" id="sdo-das-xml.examples.getSequence">
<![CDATA[
<?php
try {
$xmldas = SDO_DAS_XML::create("letter.xsd");
try {
$do = $xmldas->createDataObject("http://letterSchema", "FormLetter");
$seq = $do->getSequence();
$seq->insert("April 09, 2005", NULL, 'date');
$seq->insert("Acme Inc. ", NULL, NULL);
$seq->insert("United Kingdom. ");
$seq->insert("Dear", NULL, NULL);
$seq->insert("Tarun", NULL, "firstName");
$seq->insert("Nayaraaa", NULL, "lastName");
$do->lastName = "Nayar";
$seq->insert("Please note that your order number ");
$seq->insert(12345);
$seq->insert(" has been dispatched today. Thanks for your business with us.");
$type = $do->getType();
print($xmldas->saveDataObjectToString($do, $type[0], $type[1]));
} catch (SDO_Exception $e) {
print($e);
}
} catch (SDO_TypeNotFoundException $e) {
print("Type is not defined in the xsd file");
} catch (SDO_DAS_XML_ParserException $e) {
print("Problem while parsing");
}
?>
]]>
</programlisting>
</example>
<example>
<title>Working with the SDO_DAS_XML_Document Class</title>
<para>
This example shows you how to use the SDO_DAS_XML_Document class.
SDO_DAS_XML_Document class is provided to get/set
XML declarations such as version, schema location, encoding etc.
</para>
<programlisting role="php" id="sdo-das-xml.examples.sdo_das_xml_document">
<![CDATA[
<?php
try {
$xmldas = SDO_DAS_XML::create("letter.xsd");
$xdoc = $xmldas->loadFromFile("letter.xml");
print("Encoding is set to : " . $xdoc->getEncoding());
print("XML Version : " . $xdoc->getXMLVersion();
$xdoc->setXMLVersion("1.1");
print($xmldas->saveDocumentToString($xdoc));
} catch (SDO_TypeNotFoundException $e) {
print("Type is not defined in the xsd file");
} catch (SDO_DAS_XML_ParserException $e) {
print("Problem while parsing");
}
?>
]]>
</programlisting>
</example>
</section>
<!-- class definition section -->
<section id='sdo-das-xml.classes'>
&reftitle.classes;
<para>
The XML DAS provides three classes.
The SDO_DAS_XML which is the main class used to fetch the
data from the XML source and also can used to write the data back.
The next one is SDO_DAS_XML_Document class,
which is basically useful to get/set the XML declarations such as
encoding, version etc.
And the last class is SDO_DAS_XML_ParserException which will
be thrown for any parser exceptions while loading xsd/xml file.
</para>
<section id='sdo-das-xml.class.sdo_das_xml'>
<title>
<classname>SDO_DAS_XML</classname>
</title>
<para>
This is the main class of XML DAS,
which is used fetch the data from the xml source
and also used to write the data back.
Other than the methods to load and save xml files,
it also has a method called createDataObject
which can be used to create an empty DataObject of a given type.
</para>
<section id='sdo-das-xml.class.SDO_DAS_XML.methods'> &reftitle.methods;
<itemizedlist>
<listitem>
<para>
<link linkend='function.SDO-DAS-XML-create'>create</link>
This is the only static method available in SDO_DAS_XML class.
Used to construct SDO_DAS_XML object.
</para>
</listitem>
<listitem>
<para>
<link linkend='function.SDO-DAS-XML-createDataObject'>
createDataObject
</link>
Can be used to construct the DataObject of a given type.
</para>
</listitem>
<listitem>
<para>
<link linkend='function.SDO-DAS-XML-loadFromFile'>
loadFromFile
</link>
Loads the xml instance document from a file.
This file can be at local file system or it can be on a remote host.
</para>
</listitem>
<listitem>
<para>
<link linkend='function.SDO-DAS-XML-loadFromString'>
loadFromString
</link>
same as the above method.
Loads the xml instance which is available as string.
</para>
</listitem>
<listitem>
<para>
<link linkend='function.SDO-DAS-XML-saveDataObjectToFile'>
saveDataObjectToFile
</link>
save SDO_DataObject to a file.
</para>
</listitem>
<listitem>
<para>
<link linkend='function.SDO-DAS-XML-saveDataObjectToString'>
saveDataObjectToString
</link>
save SDO_DataObject to a xml file.
</para>
</listitem>
<listitem>
<para>
<link linkend='function.SDO-DAS-XML-saveDocumentToFile'>
saveDocumentToFile
</link>
save SDO_DAS_XML_Document object as a xml file.
</para>
</listitem>
<listitem>
<para>
<link linkend='function.SDO-DAS-XML-saveDocumentToString'>
saveDocumentToString
</link>
save SDO_DAS_XML_Document object as a xml string.
</para>
</listitem>
</itemizedlist>
</section>
</section>
<section id='sdo-das-xml.class.sdo_das_xml_document'>
<title>
<classname>SDO_DAS_XML_Document</classname>
</title>
<para>
This class can be used to get/set XML Declarations such as encoding,
schema location etc.
</para>
<section id='sdo-das-xml.class.SDO_DAS_XML_Document.methods'>
&reftitle.methods;
<itemizedlist>
<listitem>
<para>
<link linkend='function.SDO-DAS-XML-Document-getEncoding'>
getEncoding
</link>
gets the encoding string.
</para>
</listitem>
<listitem>
<para>
<link linkend='function.SDO-DAS-XML-Document-getNoNamespaceSchemaLocation'>
getNoNamespaceSchemaLocation
</link>
gets the no namespace schema location.
</para>
</listitem>
<listitem>
<para>
<link linkend='function.SDO-DAS-XML-Document-getRoorDataObject'>
getRootDataObject
</link>
gets the root DataObject.
</para>
</listitem>
<listitem>
<para>
<link linkend='function.SDO-DAS-XML-Document-getRootElementName'>
getRootElementName
</link>
gets the root DataObject's name.
</para>
</listitem>
<listitem>
<para>
<link linkend='function.SDO-DAS-XML-Document-getRootElementURI'>
getRootElementURI
</link>
gets the root DataObject's URI.
</para>
</listitem>
<listitem>
<para>
<link linkend='function.SDO-DAS-XML-Document-getSchemaLocation'>
getSchemaLocation
</link>
gets schema location.
</para>
</listitem>
<listitem>
<para>
<link linkend='function.SDO-DAS-XML-Document-getXMLDeclaration'>
getXMLDeclaration
</link>
gets whether xml declaration is set ot not.
</para>
</listitem>
<listitem>
<para>
<link linkend='function.SDO-DAS-XML-Document-getXMLVersion'>
getXMLVersion
</link>
gets the xml version.
</para>
</listitem>
<listitem>
<para>
<link linkend='function.SDO-DAS-XML-Document-setEncoding'>
setEncoding
</link>
sets the encoding string with the given value.
</para>
</listitem>
<listitem>
<para>
<link linkend='function.SDO-DAS-XML-Document-setNoNamespaceSchemaLocation'>
setNoNamespaceSchemaLocation
</link>
sets the no namespace schema location with the given value.
</para>
</listitem>
<listitem>
<para>
<link linkend='function.SDO-DAS-XML-Document-setSchemaLocation'>
setSchemaLocation
</link>
sets the schema location with the given value.
</para>
</listitem>
<listitem>
<para>
<link linkend='function.SDO-DAS-XML-Document-setXMLDeclaration'>
setXMLDeclaraion
</link>
to set/unset the xml declaration.
</para>
</listitem>
<listitem>
<para>
<link linkend='function.SDO-DAS-XML-Document-setXMLVersion'>
setXMLVersion
</link>
sets the xml version with the given value.
</para>
</listitem>
</itemizedlist>
</section>
</section>
<section id='sdo-das-xml.class.sdo_das_xml_parserexception'>
<title>
<classname>SDO_DAS_XML_ParserException</classname>
</title>
<para>
Is a subclass of
<classname>SDO_Exception</classname>
.
Thrown for any parser errors while loading the xsd/xml file.
</para>
</section>
</section>
</partintro>
&reference.sdo-das-xml.functions;
</reference>
<!-- 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:"../../../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
-->