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

📄 sdo-das-xml.examples.html

📁 php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容
💻 HTML
📖 第 1 页 / 共 4 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>Examples</title>  <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="sdo-das-xml.constants.html">Predefined Constants</a></div> <div class="next" style="text-align: right; float: right;"><a href="ref.sdo-das-xml.html">SDO DAS XML Functions</a></div> <div class="up"><a href="book.sdo-das-xml.html">SDO DAS XML</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div> <h1>Examples</h1>   <p class="para">    Several of the following examples are based on the    <a href="sdo.sample.sequence.html" class="link">letter example</a>    described in the    <a href="ref.sdo.html" class="link">SDO documentation</a>.    The examples assume the XML Schema for the letter is contained in a file    <var class="filename">letter.xsd</var>    and the letter instance is in the file    <var class="filename">letter.xml</var>.    These two files are reproduced here:   </p>   <p class="para">    <div class="example-contents"><div class="cdata"><pre>&lt;xsd:schema xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;  xmlns:letter=&quot;http://letterSchema&quot;  targetNamespace=&quot;http://letterSchema&quot;&gt;  &lt;xsd:element name=&quot;letters&quot; type=&quot;letter:FormLetter&quot;/&gt;  &lt;xsd:complexType name=&quot;FormLetter&quot; mixed=&quot;true&quot;&gt;    &lt;xsd:sequence&gt;      &lt;xsd:element name=&quot;date&quot; minOccurs=&quot;0&quot; type=&quot;xsd:string&quot;/&gt;      &lt;xsd:element name=&quot;firstName&quot; minOccurs=&quot;0&quot; type=&quot;xsd:string&quot;/&gt;      &lt;xsd:element name=&quot;lastName&quot; minOccurs=&quot;0&quot; type=&quot;xsd:string&quot;/&gt;    &lt;/xsd:sequence&gt;  &lt;/xsd:complexType&gt;&lt;/xsd:schema&gt;</pre></div>    </div>   </p>    <p class="para">    <div class="example-contents"><div class="cdata"><pre>&lt;letter:letters xmlns:letter=&quot;http://letterSchema&quot;&gt;  &lt;date&gt;March 1, 2005&lt;/date&gt;  Mutual of Omaha  Wild Kingdom, USA  Dear  &lt;firstName&gt;Casy&lt;/firstName&gt;  &lt;lastName&gt;Crocodile&lt;/lastName&gt;  Please buy more shark repellent.  Your premium is past due.&lt;/letter:letters&gt;</pre></div>    </div>   </p>       <div class="example">    <p><b>Example #1 Loading, altering, and saving an XML document</b></p>        <div class="example-contents"><p>     The following example shows how an XML document can be loaded from a file,     altered, and written back.     </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;Load,&nbsp;update,&nbsp;and&nbsp;save&nbsp;an&nbsp;XML&nbsp;document<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;</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">$root_data_object&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$document</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getRootDataObject</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$root_data_object</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">date&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"September&nbsp;03,&nbsp;2004"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$root_data_object</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">firstName&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Anantoju"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$root_data_object</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">lastName&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Madhu"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$xmldas</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">saveFile</span><span style="color: #007700">(</span><span style="color: #0000BB">$document</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"letter-out.xml"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"New&nbsp;file&nbsp;has&nbsp;been&nbsp;written:\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;print&nbsp;</span><span style="color: #0000BB">file_get_contents</span><span style="color: #007700">(</span><span style="color: #DD0000">"letter-out.xml"</span><span style="color: #007700">);<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: #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 class="example-contents"><p>     An instance of the XML DAS is first obtained from the      <a href="function.sdo-das-xml-create.html" class="function">SDO_DAS_XML::create()</a>     method,      which is a static method of the      <b class="classname">SDO_DAS_XML</b>     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      <b>loadFile()</b>     method.     There is also a      <b>loadString()</b>     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      <b class="classname">SDO_DAS_XML_Document</b>,     on which you can call the      <b>getRootDataObject()</b>     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      <var class="varname"><a href="function.date.html" class="classname">date</a></var>,      <var class="varname">firstName</var>, and     <var class="varname">lastName</var> properties.     Then we use the      <b>saveFile()</b>     method to write the changed document back to the file system.     The saveFile method has an optional extra integer argument which if specified     will cause the XML DAS to format the XML, using the integer as the amount to      indent by at each change in level on the document.     </p></div>    <div class="example-contents"><p>     This will write the following to <var class="filename">letter-out.xml</var>.    </p></div>    <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;September 03, 2004&lt;/date&gt;  Mutual of Omaha  Wild Kingdom, USA  Dear  &lt;firstName&gt;Anantoju&lt;/firstName&gt;  &lt;lastName&gt;Madhu&lt;/lastName&gt;  Please buy more shark repellent.  Your premium is past due.&lt;/FormLetter&gt; </pre></div>   </div>       </div>   <div class="example">    <p><b>Example #2 Creating a new XML document</b></p>

⌨️ 快捷键说明

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