📄 sdo-das-xml.examples.html
字号:
<element name= "name" type="string"/> <element name= "length" type="positiveInteger" /> </sequence> </complexType> <complexType name="bearType"> <sequence> <element name= "name" type="string"/> <element name= "weight" type="positiveInteger" /> </sequence> </complexType> <complexType name="pantherType"> <sequence> <element name= "name" type="string"/> <element name= "colour" type="string" /> </sequence> </complexType></schema></pre></div> </div> </p></div> <div class="example-contents"><p> Here is the example PHP code that uses these two schema files: </p></div> <div class="example-contents"><p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /><br /></span><span style="color: #FF8000">/**<br /> * Illustrate open types and the use of the addTypes() method<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">();<br /></span><span style="color: #0000BB">$xmldas</span><span style="color: #007700">-></span><span style="color: #0000BB">addTypes</span><span style="color: #007700">(</span><span style="color: #DD0000">"jungle.xsd"</span><span style="color: #007700">); </span><span style="color: #FF8000">// this is an open type i.e. the xsd specifies it can contain "any" type<br /></span><span style="color: #0000BB">$xmldas</span><span style="color: #007700">-></span><span style="color: #0000BB">addTypes</span><span style="color: #007700">(</span><span style="color: #DD0000">'animalTypes.xsd'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$baloo </span><span style="color: #007700">= </span><span style="color: #0000BB">$xmldas</span><span style="color: #007700">-></span><span style="color: #0000BB">createDataObject</span><span style="color: #007700">(</span><span style="color: #DD0000">''</span><span style="color: #007700">,</span><span style="color: #DD0000">'bearType'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$baloo</span><span style="color: #007700">-></span><span style="color: #0000BB">name </span><span style="color: #007700">= </span><span style="color: #DD0000">"Baloo"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$baloo</span><span style="color: #007700">-></span><span style="color: #0000BB">weight </span><span style="color: #007700">= </span><span style="color: #0000BB">800</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$bagheera </span><span style="color: #007700">= </span><span style="color: #0000BB">$xmldas</span><span style="color: #007700">-></span><span style="color: #0000BB">createDataObject</span><span style="color: #007700">(</span><span style="color: #DD0000">''</span><span style="color: #007700">,</span><span style="color: #DD0000">'pantherType'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$bagheera</span><span style="color: #007700">-></span><span style="color: #0000BB">name </span><span style="color: #007700">= </span><span style="color: #DD0000">"Bagheera"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$bagheera</span><span style="color: #007700">-></span><span style="color: #0000BB">colour </span><span style="color: #007700">= </span><span style="color: #DD0000">'inky black'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$kaa </span><span style="color: #007700">= </span><span style="color: #0000BB">$xmldas</span><span style="color: #007700">-></span><span style="color: #0000BB">createDataObject</span><span style="color: #007700">(</span><span style="color: #DD0000">''</span><span style="color: #007700">,</span><span style="color: #DD0000">'snakeType'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$kaa</span><span style="color: #007700">-></span><span style="color: #0000BB">name </span><span style="color: #007700">= </span><span style="color: #DD0000">"Kaa"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$kaa</span><span style="color: #007700">-></span><span style="color: #0000BB">length </span><span style="color: #007700">= </span><span style="color: #0000BB">25</span><span style="color: #007700">;<br /><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">createDocument</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$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 /></span><span style="color: #0000BB">$do</span><span style="color: #007700">-></span><span style="color: #0000BB">bear </span><span style="color: #007700">= </span><span style="color: #0000BB">$baloo</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$do</span><span style="color: #007700">-></span><span style="color: #0000BB">panther </span><span style="color: #007700">= </span><span style="color: #0000BB">$bagheera</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$do</span><span style="color: #007700">-></span><span style="color: #0000BB">snake </span><span style="color: #007700">= </span><span style="color: #0000BB">$kaa</span><span style="color: #007700">;<br /><br />print(</span><span style="color: #0000BB">$xmldas</span><span style="color: #007700">-></span><span style="color: #0000BB">saveString</span><span style="color: #007700">(</span><span style="color: #0000BB">$document</span><span style="color: #007700">,</span><span style="color: #0000BB">2</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </p></div> <div class="example-contents"><p> These two schema files are loaded into the XML DAS with first the <b>create()</b> and <b>addTypes()</b> methods. The <b>createDataObject()</b> method is used to create three separate data objects. In each case the namespaceURI and typename of the type are passed to the <b>createDataObject()</b> method: in this example the namespace URI is blank because no namespace is used in the schema. Once the three data objects - representing a bear, a panther and a snake - have been created, a document object is created with the <b>createDocument()</b> method. In this case there is no ambiguity about what the document element of the document should be - as the second schema file only defines complex types, the document element can only be the global <var class="varname">jungle</var> element defined in the first schema. This document will have a single root data object corresponding to an empty document element <var class="varname">jungle</var>. As this is an open type, properties can be added at will. When the first assignment is made to <var class="varname">$do->bear</var>, a property <var class="varname">bear</var> is added to the root data object: likewise for the next two assignments. When the document is written out by the <b>saveString()</b> method, the resulting document is: </p></div> <div class="example-contents"><p> <div class="example-contents"><div class="cdata"><pre><?xml version="1.0" encoding="UTF-8"?><jungle xsi:type="jungle" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <bear xsi:type="bearType"> <name>Baloo</name> <weight>800</weight> </bear> <panther xsi:type="pantherType"> <name>Bagheera</name> <colour>inky black</colour> </panther> <snake xsi:type="snakeType"> <name>Kaa</name> <length>25</length> </snake></jungle></pre></div> </div> </p></div> </div> <div class="example"> <p><b>Example #5 Finding out what you can from the document</b></p> <div class="example-contents"><p> This example is intended to illustrate how you can find the element name and namespace of the document element from the XML Document object, and the SDO type and namespace from the root data object of the XML data object, and how they relate to one another. This can be difficult to understand because there are four method calls: two can be made against the Document object, and two that can be made against any data object including the root data object. Because of the rules that define how the SDO model is derived from the XML model, when the data object concerned is the root object that represents the document object for the document, only three possible values can come back from these four method calls. </p></div> <div class="example-contents"><p> The two method calls that can be made against the document are <b>getRootElementName()</b> and <b>getRootEelementURI()</b>. These return the element name and namespace of the document element, respectively. </p></div> <div class="example-contents"><p> The two method calls that can be made against any data object are <b>getTypeName()</b> and <b>getTypeNamespaceURI()</b>. These return the SDO type name and type namespace of the data object, respectively. </p></div> <div class="example-contents"><p> Always, calling <b>getRootElementURI()</b> on the document object will return the same value as calling <b>getNamespaceURI()</b> on the root data object. Essentially, the information is all derived from the first few lines of the
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -