📄 sdo-das-xml.examples.html
字号:
schema file, where there are three distinct pieces of information. For illustration, here again are the first few lines of the letter.xsd that we used above. </p></div> <div class="example-contents"><div class="cdata"><pre><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"> .../...</pre></div> </div> <div class="example-contents"><p> The three important values are: <ul class="itemizedlist"> <li class="listitem"> <p class="para"> <var class="varname">letters</var>, the name of the document element </p> </li> <li class="listitem"> <p class="para"> <var class="varname">FormLetter</var>, the name of the complex type of the document element. This is also the name of the SDO type of the root data object. </p> </li> <li class="listitem"> <p class="para"> <var class="varname">http://letterSchema</var>, the namespace to which the document element belongs. This is also the namespaceURI of the SDO type of the root data object. </p> </li> </ul> It is part of the XML-SDO mapping rules that when the SDO model is built from the schema file, the typename and namespaceURI of the SDO types for the root element are taken from those of the complex type of the document element, where it exists. Hence in this example the typename of the root data object is FormLetter. In the event that there is no separate complex type definition for the document element, when the the type is defined inline and is anonymous, the SDO type name will be the same as the element name. </p></div> <div class="example-contents"><p> The following program loads the letter document and checks the return values from each of the four calls. </p></div> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">/**<br /> * Finding out what you can about the document and document element<br /> * This can be quite hard to understand because there are four calls<br /> * Two calls are made against the document<br /> * Two calls are made against the root data object and its model<br /> * Because of the SDO-XML mapping rules and how the SDO model is derived<br /> * from the XML model, only three possible values can come back from these four calls.<br /> * Always, $document->getRootElementURI() == (type of root data object)->namespaceURI <br /> * Essentially, it all comes form the first few lines of the xsd:<br /> * <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"<br /> * xmlns:letter="http://letterSchema"<br /> * targetNamespace="http://letterSchema"><br /> * <xsd:element name="letters" type="letter:FormLetter"/><br /> */<br /><br /></span><span style="color: #0000BB">$xmldas </span><span style="color: #007700">= </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 /></span><span style="color: #0000BB">$document </span><span style="color: #007700">= </span><span style="color: #0000BB">$xmldas</span><span style="color: #007700">-></span><span style="color: #0000BB">loadFile</span><span style="color: #007700">(</span><span style="color: #DD0000">"letter.xml"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$root_do </span><span style="color: #007700">= </span><span style="color: #0000BB">$document</span><span style="color: #007700">-></span><span style="color: #0000BB">getRootDataObject</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/**<br /> * The "root element name" is the element name of the document element<br /> * in this case 'letters'<br /> * This matches the 'name' attribute of the document element in the xsd and matches<br /> * the element name from the xml<br /> */<br /></span><span style="color: #007700">echo </span><span style="color: #DD0000">"The document element name is " </span><span style="color: #007700">. </span><span style="color: #0000BB">$document</span><span style="color: #007700">-></span><span style="color: #0000BB">getRootElementName</span><span style="color: #007700">() . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">assert</span><span style="color: #007700">(</span><span style="color: #0000BB">$document</span><span style="color: #007700">-></span><span style="color: #0000BB">getRootElementName</span><span style="color: #007700">() == </span><span style="color: #DD0000">'letters'</span><span style="color: #007700">); </span><span style="color: #FF8000">// a property of the document<br /><br />/**<br /> * The "root element URI" is the namespace part of the element name of the document element<br /> * in this case 'http://letterSchema' since 'letters' is in that namespace<br /> * This is taken from the xsd and matches the namespace picked up from the xml<br /> */<br /></span><span style="color: #007700">echo </span><span style="color: #DD0000">"The document element is in the namespace " </span><span style="color: #007700">. </span><span style="color: #0000BB">$document</span><span style="color: #007700">-></span><span style="color: #0000BB">getRootElementURI</span><span style="color: #007700">() . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">assert</span><span style="color: #007700">(</span><span style="color: #0000BB">$document</span><span style="color: #007700">-></span><span style="color: #0000BB">getRootElementURI</span><span style="color: #007700">() == </span><span style="color: #DD0000">'http://letterSchema'</span><span style="color: #007700">); </span><span style="color: #FF8000">// a property of the document<br /><br />/**<br /> * The type name is taken from the SDO model<br /> * The XML-SDO mapping rules make this either:<br /> * The name of the complexType if there is one (in this case there is)<br /> * The document element name if there no complexType<br /> * This is taken from the xsd <br /> */<br /></span><span style="color: #007700">echo </span><span style="color: #DD0000">"The type name of the root data object is " </span><span style="color: #007700">. </span><span style="color: #0000BB">$root_do</span><span style="color: #007700">-></span><span style="color: #0000BB">getTypeName</span><span style="color: #007700">() . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">assert</span><span style="color: #007700">(</span><span style="color: #0000BB">$root_do</span><span style="color: #007700">-></span><span style="color: #0000BB">getTypeName</span><span style="color: #007700">() == </span><span style="color: #DD0000">'FormLetter'</span><span style="color: #007700">); <br /><br /></span><span style="color: #FF8000">/**<br /> * The type's namespaceURI is taken from the SDO model<br /> * The XML-SDO mapping rules ensure that this will always be the same as <br /> * the namepace URI of the document element<br /> */<br /></span><span style="color: #007700">echo </span><span style="color: #DD0000">"The namespaceURI of the root data object is " </span><span style="color: #007700">. </span><span style="color: #0000BB">$root_do</span><span style="color: #007700">-></span><span style="color: #0000BB">getTypeNamespaceURI</span><span style="color: #007700">() . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">assert</span><span style="color: #007700">(</span><span style="color: #0000BB">$root_do</span><span style="color: #007700">-></span><span style="color: #0000BB">getTypeNamespaceURI</span><span style="color: #007700">() == </span><span style="color: #DD0000">'http://letterSchema'</span><span style="color: #007700">); <br /><br /></span><span style="color: #0000BB">?></span></span></code></div> </div> <div class="example-contents"><p> The output from this program is as follows: </p></div> <div class="example-contents"><div class="cdata"><pre>The document element name is lettersThe document element is in the namespace http://letterSchemaThe type name of the root data object is FormLetterThe namespaceURI of the root data object is http://letterSchema</pre></div> </div> </div> <div class="example"> <p><b>Example #6 Printing the SDO model</b></p> <div class="example-contents"><p> The XML DAS provides a simple means to see what types and properties have been loaded. The php "print" or "echo" instruction will print out the types and properties. </p></div> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">/**<br /> * Illustrate printing out the model<br /> */<br /><br /></span><span style="color: #0000BB">$xmldas </span><span style="color: #007700">= </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 />print </span><span style="color: #0000BB">$xmldas</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">?></span></span></code></div> </div> <div class="example-contents"><p> The output from this program is as follows: </p></div> <div class="example-contents"><div class="cdata"><pre>object(SDO_XML_DAS)#1 {18 types have been defined. The types and their properties are::1. commonj.sdo:BigDecimal2. commonj.sdo:BigInteger3. commonj.sdo:Boolean4. commonj.sdo:Byte5. commonj.sdo:Bytes6. commonj.sdo:ChangeSummary7. commonj.sdo:Character8. commonj.sdo:DataObject9. commonj.sdo:Date10. commonj.sdo:Double11. commonj.sdo:Float12. commonj.sdo:Integer13. commonj.sdo:Long14. commonj.sdo:Short15. commonj.sdo:String16. commonj.sdo:URI17. http://letterSchema:FormLetter - date (commonj.sdo:String) - firstName (commonj.sdo:String) - lastName (commonj.sdo:String)18. http://letterSchema:RootType - letters (http://letterSchema:FormLetter)</pre></div> </div> </div> </div><hr /><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></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -