mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
Various edits intended to make the examples clearer, with sample output.
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@192781 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
d08f90817e
commit
a3d58caf82
1 changed files with 179 additions and 75 deletions
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.8 $ -->
|
||||
<!-- $Revision: 1.9 $ -->
|
||||
<!-- 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>
|
||||
|
@ -23,18 +23,15 @@
|
|||
</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
|
||||
application and an XML data source, which can be either a file or
|
||||
a URL. In order to do this it needs to be told the location of the
|
||||
XML schema, which is passed as a parameter to the create
|
||||
method of the XML DAS.
|
||||
The schema 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">
|
||||
|
@ -45,7 +42,7 @@
|
|||
SDO to have been installed.
|
||||
See the
|
||||
<link linkend="sdo.installation">SDO installation instructions</link>
|
||||
for steps on how to do this.
|
||||
for the details of how to do this.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
|
@ -246,36 +243,54 @@
|
|||
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>
|
||||
.
|
||||
<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>
|
||||
.
|
||||
<filename>letter.xml</filename>.
|
||||
These two files are reproduced here:
|
||||
</para>
|
||||
<para>
|
||||
<programlisting role="xml">
|
||||
<![CDATA[
|
||||
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:letter="http://letterSchema"
|
||||
targetNamespace="http://letterSchema">
|
||||
<xsd:element name="letters" type="letter:FormLetter"/>
|
||||
<xsd:complexType name="FormLetter" mixed="true">
|
||||
<xsd:sequence>
|
||||
<xsd:element name="date" minOccurs="0" type="xsd:string"/>
|
||||
<xsd:element name="firstName" minOccurs="0" type="xsd:string"/>
|
||||
<xsd:element name="lastName" minOccurs="0" type="xsd:string"/>
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
</xsd:schema>
|
||||
]]>
|
||||
</programlisting>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<programlisting role="xml">
|
||||
<![CDATA[
|
||||
<letter:letters xmlns:letter="http://letterSchema">
|
||||
<date>March 1, 2005</date>
|
||||
Mutual of Omaha
|
||||
Wild Kingdom, USA
|
||||
Dear
|
||||
<firstName>Casy</firstName>
|
||||
<lastName>Crocodile</lastName>
|
||||
Please buy more shark repellent.
|
||||
Your premium is past due.
|
||||
</letter:letters>
|
||||
]]>
|
||||
</programlisting>
|
||||
</para>
|
||||
|
||||
<example>
|
||||
<title>Working with the SDO_DAS_XML Class</title>
|
||||
<title>Loading, altering, and saving an XML document</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.
|
||||
The following example shows how an XML document can be loaded from a file,
|
||||
altered, and written back.
|
||||
</para>
|
||||
<programlisting role="php" id="sdo-das-xml.examples.loadfromfile">
|
||||
<![CDATA[
|
||||
|
@ -296,52 +311,73 @@ try {
|
|||
?>
|
||||
]]>
|
||||
</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.
|
||||
An instance of the XML DAS is first obtained from the
|
||||
<function>SDO_DAS_XML::create</function>
|
||||
method,
|
||||
which is a static method of the
|
||||
<classname>SDO_DAS_XML</classname>
|
||||
class.
|
||||
The location of the xsd is passed as a parameter.
|
||||
Once we have an instance of the XML DAS initialised
|
||||
with a given schema,
|
||||
we can use it to load the instance document using the
|
||||
<function>loadFromFile</function>
|
||||
method.
|
||||
There is also a
|
||||
<function>loadFromString</function>
|
||||
method if you want to load an XML
|
||||
instance document from a string.
|
||||
If the instance document loads successfully,
|
||||
you will be returned an object of type
|
||||
<classname>SDO_DAS_XML_Document</classname>,
|
||||
on which you can call the
|
||||
<function>getRootDataObject</function>
|
||||
method to get the SDO data object which is the root
|
||||
of the SDO data graph.
|
||||
You can then use SDO operations to change the graph.
|
||||
In this example we alter the
|
||||
<varname>date</varname>,
|
||||
<varname>firstName</varname>, and
|
||||
<varname>lastName</varname> properties.
|
||||
Then we use the
|
||||
<function>saveDocumentToFile</function>
|
||||
method to write the changed document back to the file system.
|
||||
</para>
|
||||
<programlisting role="php" id="sdo-das-xml.examples.createDataObject">
|
||||
<para>
|
||||
This will write the following to <filename>letter-out.xml</filename>.
|
||||
</para>
|
||||
<programlisting role="xml" id="sdo-das-xml.examples.loadfromfile.output">
|
||||
<![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);
|
||||
?>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<FormLetter xmlns="http://letterSchema" xsi:type="FormLetter" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<date>September 03, 2004</date>
|
||||
Mutual of Omaha
|
||||
Wild Kingdom, USA
|
||||
Dear
|
||||
<firstName>Anantoju</firstName>
|
||||
<lastName>Madhu</lastName>
|
||||
Please buy more shark repellent.
|
||||
Your premium is past due.
|
||||
</FormLetter>
|
||||
]]>
|
||||
</programlisting>
|
||||
</programlisting>
|
||||
|
||||
</example>
|
||||
|
||||
<example>
|
||||
<title>Working with the SDO_DAS_XML Class</title>
|
||||
<title>Creating a new XML document</title>
|
||||
<para>
|
||||
This example shows you how to create the DataObject and use
|
||||
the Sequence API (
|
||||
The previous example loaded the document from a file.
|
||||
This example shows how to create an SDO data graph in memory.
|
||||
In this example it is then saved to an XML string.
|
||||
Furthermore, because the letter contains both structured and
|
||||
unstructured content, it uses
|
||||
<link linkend="sdo.sample.sequence">
|
||||
For more information on Sequence API
|
||||
the Sequence API
|
||||
</link>
|
||||
) to construct a letter containing unstructured text.
|
||||
as well assignments to properties to construct the data graph.
|
||||
</para>
|
||||
<programlisting role="php" id="sdo-das-xml.examples.getSequence">
|
||||
<programlisting role="php" id="sdo-das-xml.examples.create">
|
||||
<![CDATA[
|
||||
<?php
|
||||
try {
|
||||
|
@ -373,12 +409,31 @@ try {
|
|||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
<para>
|
||||
This will emit the following output (line breaks have been inserted for readability):
|
||||
</para>
|
||||
<programlisting role="xml" id="sdo-das-xml.examples.create.output">
|
||||
<![CDATA[
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<FormLetter xmlns="http://letterSchema" xsi:type="FormLetter"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<date>April 09, 2005</date>
|
||||
Acme Inc. United Kingdom.
|
||||
Dear
|
||||
<firstName>Tarun</firstName>
|
||||
<lastName>Nayar</lastName>
|
||||
Please note that your order number 12345 has been
|
||||
dispatched today. Thanks for your business with us.
|
||||
</FormLetter>
|
||||
]]>
|
||||
</programlisting>
|
||||
<example>
|
||||
<title>Working with the SDO_DAS_XML_Document Class</title>
|
||||
<title>Setting XML document properties</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.
|
||||
This third example shows you how to use the SDO_DAS_XML_Document class.
|
||||
SDO_DAS_XML_Document class is provided to get and set
|
||||
properties of the XML declaration such as version, schema location,
|
||||
encoding and so on.
|
||||
</para>
|
||||
<programlisting role="php" id="sdo-das-xml.examples.sdo_das_xml_document">
|
||||
<![CDATA[
|
||||
|
@ -386,8 +441,8 @@ try {
|
|||
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();
|
||||
print("Encoding is set to : " . $xdoc->getEncoding() . "\n");
|
||||
print("XML Version : " . $xdoc->getXMLVersion() . "\n");
|
||||
$xdoc->setXMLVersion("1.1");
|
||||
print($xmldas->saveDocumentToString($xdoc));
|
||||
} catch (SDO_TypeNotFoundException $e) {
|
||||
|
@ -398,6 +453,20 @@ try {
|
|||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
The first three lines of output show how the encoding and
|
||||
XML version has been obtained from the document,
|
||||
and how the XML version has been set in the XML header.
|
||||
</para>
|
||||
<programlisting role="xml" id="sdo-das-xml.examples.sdo_das_xml_document.output">
|
||||
<![CDATA[
|
||||
Encoding is set to : UTF-8
|
||||
XML Version : 1.0
|
||||
<?xml version="1.1" encoding="UTF-8"?>
|
||||
...
|
||||
]]>
|
||||
</programlisting>
|
||||
|
||||
</example>
|
||||
</section>
|
||||
|
||||
|
@ -648,6 +717,41 @@ try {
|
|||
&reference.sdo-das-xml.functions;
|
||||
</reference>
|
||||
|
||||
<!--
|
||||
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->n
|
||||
ame = "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
|
||||
|
||||
-->
|
||||
|
||||
<!-- Keep this comment at the end of the file
|
||||
Local variables:
|
||||
mode: sgml
|
||||
|
|
Loading…
Reference in a new issue