⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdo-das-xml.examples.html

📁 php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容
💻 HTML
📖 第 1 页 / 共 4 页
字号:
    <div class="example-contents"><p>     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     <a href="sdo.sample.sequence.html" class="link">the Sequence API</a>     as well assignments to properties to construct the data graph.    </p></div>    <div class="example-contents">     <div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/**<br />&nbsp;*&nbsp;Create&nbsp;an&nbsp;XML&nbsp;document&nbsp;from&nbsp;scratch<br />&nbsp;*/<br /></span><span style="color: #007700">try&nbsp;{<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$xmldas&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">SDO_DAS_XML</span><span style="color: #007700">::</span><span style="color: #0000BB">create</span><span style="color: #007700">(</span><span style="color: #DD0000">"letter.xsd"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;try&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$doc&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$xmldas</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">createDocument</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$rdo&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$doc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getRootDataObject</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$seq&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$rdo</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getSequence</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$seq</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">insert</span><span style="color: #007700">(</span><span style="color: #DD0000">"April&nbsp;09,&nbsp;2005"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">NULL</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'date'</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$seq</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">insert</span><span style="color: #007700">(</span><span style="color: #DD0000">"Acme&nbsp;Inc.&nbsp;"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">NULL</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">NULL</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$seq</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">insert</span><span style="color: #007700">(</span><span style="color: #DD0000">"United&nbsp;Kingdom.&nbsp;"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$seq</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">insert</span><span style="color: #007700">(</span><span style="color: #DD0000">"Dear"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">NULL</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">NULL</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$seq</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">insert</span><span style="color: #007700">(</span><span style="color: #DD0000">"Tarun"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">NULL</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"firstName"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$seq</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">insert</span><span style="color: #007700">(</span><span style="color: #DD0000">"Nayaraaa"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">NULL</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"lastName"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$rdo</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">lastName&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Nayar"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$seq</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">insert</span><span style="color: #007700">(</span><span style="color: #DD0000">"Please&nbsp;note&nbsp;that&nbsp;your&nbsp;order&nbsp;number&nbsp;"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$seq</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">insert</span><span style="color: #007700">(</span><span style="color: #0000BB">12345</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$seq</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">insert</span><span style="color: #007700">(</span><span style="color: #DD0000">"&nbsp;has&nbsp;been&nbsp;dispatched&nbsp;today.&nbsp;Thanks&nbsp;for&nbsp;your&nbsp;business&nbsp;with&nbsp;us."</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print(</span><span style="color: #0000BB">$xmldas</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">saveString</span><span style="color: #007700">(</span><span style="color: #0000BB">$doc</span><span style="color: #007700">));<br />&nbsp;&nbsp;&nbsp;}&nbsp;catch&nbsp;(</span><span style="color: #0000BB">SDO_Exception&nbsp;$e</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print(</span><span style="color: #0000BB">$e</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;}<br />}&nbsp;catch&nbsp;(</span><span style="color: #0000BB">SDO_Exception&nbsp;$e</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;print(</span><span style="color: #DD0000">"Problem&nbsp;creating&nbsp;an&nbsp;XML&nbsp;document:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$e</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getMessage</span><span style="color: #007700">());<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>    </div>   </div>   <p class="para">    The     <b>createDocument()</b>    method on the XML DAS returns a document object     with a single root data object corresponding to an empty document element.     The element name of the document element is known from the schema file.     If there is any ambiguity about what the document element is, as there can be     when more than one schema has been loaded into the same XML DAS,     the element name and the namespace URI can be passed to the     <b>createDocument()</b>     method.   </p>   <p class="para">    This will emit the following output (line breaks have been inserted for readability):   </p>   <div class="example-contents">     <div class="cdata"><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&lt;FormLetter xmlns=&quot;http://letterSchema&quot; xsi:type=&quot;FormLetter&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&gt;&lt;date&gt;April 09, 2005&lt;/date&gt;Acme Inc. United Kingdom. Dear&lt;firstName&gt;Tarun&lt;/firstName&gt;&lt;lastName&gt;Nayar&lt;/lastName&gt;Please note that your order number 12345 has been dispatched today. Thanks for your business with us.&lt;/FormLetter&gt;</pre></div>   </div>   <div class="example">    <p><b>Example #3 Setting XML document properties</b></p>    <div class="example-contents"><p>     This third example shows you how to set the XML version and     encoding on the document object.      These will be used when the XML is written out.     If no XML declaration is wanted at all     (perhaps you want to generate the XML as a string to embed     in something) then you can use the      <b>setXMLDeclaration()</b>     method to suppress it.     </p></div>    <div class="example-contents">     <div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/**<br />&nbsp;*&nbsp;Illustrate&nbsp;the&nbsp;calls&nbsp;that&nbsp;control&nbsp;the&nbsp;XML&nbsp;declaration<br />&nbsp;*/<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$xmldas&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">SDO_DAS_XML</span><span style="color: #007700">::</span><span style="color: #0000BB">create</span><span style="color: #007700">(</span><span style="color: #DD0000">"letter.xsd"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$document&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$xmldas</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">loadFile</span><span style="color: #007700">(</span><span style="color: #DD0000">"letter.xml"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$document</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setXMLVersion</span><span style="color: #007700">(</span><span style="color: #DD0000">"1.1"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$document</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setEncoding</span><span style="color: #007700">(</span><span style="color: #DD0000">"ISO-8859-1"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;print(</span><span style="color: #0000BB">$xmldas</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">saveString</span><span style="color: #007700">(</span><span style="color: #0000BB">$document</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>    </div>    <div class="example-contents"><p>     The XML version and encoding are set in the XML declaration at the top      of the XML document.    </p></div>    <div class="example-contents"><div class="cdata"><pre>&lt;?xml version=&quot;1.1&quot; encoding=&quot;ISO-8859-1&quot;?&gt;.../...</pre></div>   </div>       </div>         <div class="example">    <p><b>Example #4 Using an open type</b></p>    <div class="example-contents"><p>     This fourth example illustrates the use of an SDO open type      and the use of the      <b>createDataObject()</b>     method.     For this example we use the following two      schema:   </p></div>   <div class="example-contents"><p>    <div class="example-contents"><div class="cdata"><pre>&lt;schema  xmlns=&quot;http://www.w3.org/2001/XMLSchema&quot;&gt;    &lt;element name=&quot;jungle&quot;&gt;    &lt;complexType&gt;      &lt;sequence&gt;        &lt;any minOccurs=&quot;0&quot; maxOccurs=&quot;unbounded&quot;/&gt;      &lt;/sequence&gt;    &lt;/complexType&gt;  &lt;/element&gt;  &lt;/schema&gt;</pre></div>    </div>   </p></div>   <div class="example-contents"><p>     Note the presence of the      <var class="varname">any</var>      element in the definition.     This first schema defines the      <var class="varname">jungle</var>      complex type as containing a sequence of      any other type.      The other types that the example will use are defined in a      second schema file:    </p></div>        <div class="example-contents"><p>    <div class="example-contents"><div class="cdata"><pre>&lt;schema xmlns= &quot;http://www.w3.org/2001/XMLSchema&quot;&gt;   &lt;complexType name=&quot;snakeType&quot;&gt;     &lt;sequence&gt;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -