Advarsel |
Denne udvidelse er EKSPERIMENTABEL. Virkemåden af denne udvidelse -- inklusiv navnene på des funktioner og alt andet dokumenteret om udvidelsen -- ændres muligvis uden advarsel, i en fremtidig version af PHP. Brug af denne udvidelse er på ejet ansvar. |
In order to use the XML Data Access Service for Service Data Objects, you will need to understand some of the concepts behind SDO: the data graph, the data object, XPath and property expressions, and so on. If you are not familiar with these ideas, you might want to look first at the section on SDO .
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 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.
The XML DAS currently supports reading/writing XML to/from a file or an http URL (for example, to support RSS feeds).
The SDO XML Data Access Service requires PHP 5.1 or higher. It is packaged with the SDO extension and requires SDO to have been installed. See the SDO installation instructions for steps on how to do this.
The XML Data Access Service is packaged and installed as part of the SDO extension . There are additional installations steps required.
The SDO 2.0 specification defines the mapping between XML types and SDO types. With Java SDO, this mapping is implemented by the XMLHelper. With SDO for PHP, this mapping is implemented by the XML Data Access Services. The XML DAS implements the mapping described in the SDO 2.0 specification with the following restrictions:
Simple Type with abstract="true" - no PHP support for SDO abstract types.
Simple Type with sdoJava:instanceClass - no PHP equivalent provided.
Simple Type with sdoJava:extendedInstanceClass - no PHP equivalent provided.
Simple Type with list of itemType.
Simple Type with union.
Complex Type with abstract="true" - no PHP support for SDO abstract types.
Complex Type with sdo:aliasName - no PHP support for SDO Type aliases.
Complex Type with open content - no PHP support for SDO open types.
Complex Type with open attribute - no PHP support for SDO open types.
Attribute with sdo:aliasName - no PHP support for SDO property aliases.
Attribute with default value - no PHP support for SDO property defaults.
Attribute with fixed value - no PHP support for SDO read-only properties or default values.
Attribute reference.
Attribute with sdo:string - no support for sdo:string="true".
Attribute referencing a DataObject with sdo:propertyType - no support for sdo:propertyType="...".
Attribute with bi-directional property to a DataObject with sdo:oppositeProperty and sdo:propertyType - no PHP support for SDO opposite.
Element with sdo:aliasName - no PHP support for SDO property aliases.
Element reference.
Element with nillable.
Element with substitution group.
Element of SimpleType with default - no PHP support for SDO defaults
Element of SimpleType with fixed value - - no PHP support for SDO read-only properties or default values.
Element of SimpleType with sdo:string - no support for sdo:string="true".
Element referencing a DataObject with sdo:propertyType - no support for sdo:propertyType="..."
Element with bi-directional reference to a DataObject with sdo:oppositeProperty and sdo:propertyType - no PHP support for SDO opposite.
The following examples are based on the letter example described in the SDO documentation . The examples assume the XML Schema for the letter is contained in a the file letter.xsd and the letter instance is in the file letter.xml .
Eksempel 2. Working with the SDO_DAS_XML Class The above example shown, how to use the SDO_XML_DAS 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(( company.xsd )) as defined in SDO samples section.
|
Eksempel 3. Working with the SDO_DAS_XML Class This example shows you how to create the DataObject and use the Sequence API ( For more information on Sequence API ) to construct a letter containing unstructured text.
|
Eksempel 4. Working with the SDO_DAS_XML_Document Class 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.
|
The XML DAS provides three classes. The SDO_DAS_XML which is the main class used to fetch the data from the XML source and also can used to write the data back. The next one is SDO_DAS_XML_Document class, which is basically useful to get/set the XML declarations such as encoding, version etc. And the last class is SDO_DAS_XML_ParserException which will be thrown for any parser exceptions while loading xsd/xml file.
This is the main class of XML DAS, which is used fetch the data from the xml source and also used to write the data back. Other than the methods to load and save xml files, it also has a method called createDataObject which can be used to create an empty DataObject of a given type.
create This is the only static method available in SDO_DAS_XML class. Used to construct SDO_XML_DAS object.
createDataObject Can be used to construct the DataObject of a given type.
loadFromFile Loads the xml instance document from a file. This file can be at local file system or it can be on a remote host.
loadFromString same as the above method. loads the xml instance which is available as string.
saveDataObjectToFile save SDO_DataObject to a file.
saveDataObjectToString save SDO_DataObject to a xml file.
saveDocumentToFile save SDO_DAS_XML_Document object as a xml file.
saveDocumentToString save SDO_DAS_XML_Document object as a xml string.
This class can be used to get/set XML Declarations such as encoding, schema location etc.
getEncoding gets the encoding string.
getNoNamespaceSchemaLocation gets the no namespace schema location.
getRootDataObject gets the root DataObject.
getRootElementName gets the root DataObject's name.
getRootElementURI gets the root DataObject's URI.
getSchemaLocation gets schema location.
getXMLDeclaration gets whether xml declaration is set ot not.
getXMLVersion gets the xml version.
setEncoding sets the encoding string with the given value.
setNoNamespaceSchemaLocation sets the no namespace schema location with the given value.
setSchemaLocation sets the schema location with the given value.
setXMLDeclaraion to set/unset the xml declaration.
setXMLVersion sets the xml version with the given value.
Is a subclass of SDO_Exception . Thrown for any parser errors while loading the xsd/xml file.