XML - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

XML

Description:

http://localhost/csp/user/package.class.cls. NAMESPACE Essentially a domain name ... Parameter LOCATION = 'http://localhost/webdev/Webdev.WebServices.cls' ... – PowerPoint PPT presentation

Number of Views:47
Avg rating:3.0/5.0
Slides: 22
Provided by: billm164
Category:
Tags: xml | localhost

less

Transcript and Presenter's Notes

Title: XML


1
XML
  • XML Support in Cache 5
  • XML Export
  • XML Import
  • Xerxes 2.0 SAX Parser

2
XML Export
  • Add XML.Adapter to any class to enable support
    for XML.
  • Basically this adds a few methods and parameters
    to each class and properties of that class
  • It also allows you to generate a DTD or XMLSchema
    for the class for export

3
..XMLExport(format)
  • XMLExport() outputs the contents of the class in
    either Literal or Encoded formats
  • Its an instance method so to use it you must open
    the object then call ref.XMLExport()

4
Export Methods
  • ..XMLExport()
  • Outputs to the principal device
  • ..XMLExportToString(.str)
  • Outputs to the variable str. This is limited to
    32k
  • ..XMLExportToStream(.stream)
  • Outputs to a Stream object. You would need to
    instantiate the stream variable as a reference to
    a character stream first.

5
XML Projection
  • XMLPROJECTION Element, Attribute, None
  • XMLNAME Override the name of the property
  • XMLIO IO conversion done
  • IN, INOUT, OUT
  • XSDTYPE generated based on the datatype
  • XMLKEYNAME Array Key names
  • XMLITEMNAME List collection name
  • XMLREFERENCE Dictates how references are
    projected in XML
  • ID, OID,Complete,Summary

6
XML Descriptors
  • Do class(XMLEnabled).XMLSchema()
  • Do class(XMLEnabled).XMLDTD()
  • Class Methods that export either schemas or dtds.

7
Important Notes
  • There are some limitations at the moment. I have
    a class that throws a ltFRAMESTACKgt error due to
    many sub class references we will fix this.
  • Each class can have one Projection associated
    with it. If you needed to place a property in an
    Element in one XML Export but an attribute in
    another you would need to subclass the real
    object and implement the different projections.

8
XML Import
  • Implemented in XML.Reader class
  • Can read files, streams or line by line
  • Takes the XML and correlates it with an XML
    Enabled object.
  • Can make use of a DTD or XMLSchema to validate
    the data being imported.

9
Sample Reader
Set reader class(XML.Reader).New() Set
screader.OpenString(xml) Do
reader.Correlate("org","isis.org") While
reader.Next(.org,.sc) do stuff
10
Web Services
  • What is a Web Service?
  • SOAP Protocol
  • Uses XML as the transport layer
  • Cache 5 implements full support as a SOAP Server
    and limited support as a SOAP Client.

11
Creating a Web Service
  • Add SOAP.WebService to your class. Any class can
    contain methods implemented as Web Services
  • Web Services must be ClassMethods
  • These methods must include the keyword
    webmethod
  • Service Parameters
  • LOCATION the URL for accessing the service
  • http//localhost/csp/user/package.class.cls
  • NAMESPACE Essentially a domain name
  • http//isc.org
  • SERVICENAME The name of the Service
    implementing this collection of Web Services.
  • The Signature of the Method matters! Any object
    referenced in the signature must be XML Enabled.
    Our Datatype classes are handled internally.

12
Web Service Sample
  • Here is a sample service returning an XML Enabled
    object.
  • ClassMethod GetPatient(pid As Integer) As
    Webdev.Patient WebMethod
  • set existsclass(Webdev.Patient).ExistsId(pid)
  • if 'exists quit ERR("Invalid Patient ID")
  • set refclass(Webdev.Patient).OpenId(pid)
  • quit ref

13
Web Services and Collections
  • You can return a collection of objects via a
    Service as well. To Implement this we need to
    return a List of Objects. Here is a sample class
    definition. On the following slide will appear
    the Method.
  • Class Webdev.PatientList Extends
    Library.ListOfObjects ClassType serial,
    ProcedureBlock
  • /// The type (class name) of the elements stored
    in the collection.
  • Parameter ELEMENTTYPE "Webdev.PatHolder"

14
The Method
  • ClassMethod SearchPatients(str As String) As
    Webdev.PatientList WebMethod
  • set lnP(str,","),fnP(str,",",2)
  • set rsclass(ResultSet).New("DynamicQuerySQ
    L")
  • set query"Select ID from Webdev.Patient where
    LName STARTSWITH ? and FName STARTSWITH ?"
  • do rs.Prepare(query)
  • do rs.Execute(ln,fn)
  • set listclass(Webdev.PatientList).New()
  • while rs.Next()
  • set refclass(Webdev.Patient).OpenId(rs.GetDa
    ta(1))
  • do list.Insert(ref)
  • quit list

15
Soap Client
  • Cache 5 has limited support as a consumer of SOAP
    Services
  • Implementing these allow Cache to access Web
    Services whether they are implemented via public
    web sites/.NET/or other Cache Systems

16
Implementation
  • Your classes must inherit from SOAP.WebClient
  • Parameters again these match the service
  • LOCATION
  • SERVICENAME
  • NAMESPACE
  • You can literally cut and paste with Cache
    Services.
  • Once again your methods must be class methods and
    should have to include the webmethod keyword
  • The signatures of the client and the service MUST
    be identical.
  • The method should just quit the invocation of the
    service call do the application logic elsewhere.

17
Sample Client Class Returns an Object
  • Class Webdev.WebClient Extends SOAP.WebClient
    ProcedureBlock
  • Parameter LOCATION "http//localhost/webdev/Webd
    ev.WebServices.cls"
  • Parameter NAMESPACE "http//isc.org"
  • Parameter SERVICENAME "WebServices"
  • ClassMethod GetPatient(pid As Integer) As
    Webdev.Patient WebMethod
  • Quit ..WebMethod("GetPatient").Invoke("http//isc
    .org/Webdev.WebServices.GetPatient",pid)

18
Sample Method for passing an object
ClassMethod SetPatient(pid As Webdev.Patient) As
Status WebMethod Quit ..WebMethod("SetPati
ent").Invoke("http//isc.org/Webdev.WebServices.Se
tPatient",pid)
19
Wrapping a SOAP Client call
  • All Soap requests throw a generic ltZSOAPgt error.
    Any real Error information is in the
    objlasterror variable.
  • As the internet is not a stable place it is a
    good idea to always error trap any soap requests.

20
Sample SOAP Wrapper
  • Class Webdev.SoapCalls Extends RegisteredObject
    ProcedureBlock
  • ClassMethod SearchPatients(str As String) As
    PatientList
  • set zt"SoapErrSearch"
  • set xmlclass(Webdev.WebClient).SearchPatients(
    str)
  • quit xml
  • SoapErrSearch
  • instantiate my Error object, save and quit.
  • set refclass(Webdev.Error).New(objlasterror)
  • set saveref.Save()
  • quit NULLOREF

21
Gotchas
  • C(0) Null String handling
  • Null properties are not exported by default in
    XML Export
  • IDs are not exported
Write a Comment
User Comments (0)
About PowerShow.com