Use cWebService.pkg Use DataDict.pkg Use Customer.DD Object oCustXML is a cWebService // The main purpose of this sample is to show how data can be passed in and out // as non-specified XML. // When writing your functions, always consider using structs and arrays first. These data // types could represent a simpler solution for the users and fewer lines of code // in your function. // psDocumentation provides high level documentation of your web service. Clients using // this service will see and use this documentation. Set psDocumentation to ; ("This uses a web service to return a list of customers and to pass a " +; "list of customers with items marked for delete. It is expected that the" + ; "client using this will know what the format of the XML document must be") Set psServiceName to "CustomerXML" Set psServiceURI to "http://tempuri.org/" Set psServiceTitle to "Customer XML Service" Object Customer_DD is a Customer_DataDictionary Send DefineAllExtendedFields End_Object // Customer_DD Set Main_DD to Customer_DD { Published = True } { Description = "Returns an XML document of all customers (Name, Number, State)." } Function CustomerXMLList Returns XmlHandle Integer bOk Handle hoXML hoRoot hoEle hoXML1 hoRoot1 Handle hoCustomerDD String sName sNumber sState sNamespace Move Customer_dd to hoCustomerDD // namespace to use for document Move "http://www.dataacess.com/Test/CustomerList" to sNameSpace // create XML document / Create root node Get Create U_cXMLDomDocument To hoXML // Create the Root element named CustomerList Get CreateDocumentElementNS Of hoXML sNameSpace "CustomerList" To hoRoot // now go through all customer records Send Clear of hoCustomerDD Send Find of hoCustomerDD ge 2 While (found) // get name, number and state to strings Move (trim(Customer.Name)) To sName Move Customer.Customer_Number To sNumber Move (trim(Customer.State)) To sState // for each customer create customer node with child elements Get AddElementNS Of hoRoot sNameSpace "Customer" "" To hoEle Send AddElementNS Of hoEle sNameSpace "Name" sName Send AddElementNS Of hoEle sNameSpace "Number" sNumber Send AddElementNS Of hoEle sNameSpace "State" sState Send Destroy Of hoEle Send Find of hoCustomerDD gt 2 Loop Function_Return hoXML End_Function // Pass XML customer document and parse it. Delete marked // customers. Return a new XML containing a new list of customers { Published = True } { Description = "Passed a customer XML with delete atrributes. Deletes all customers and returns a new list." } Function DelCustomerXMLList XmlHandle CustomerList Returns XmlHandle Handle hoCustomerDD Handle hoRoot hoCust Handle hoRetXml hoRetRoot hoRetCust String sDel sNumber sNs Boolean bDelete If not CustomerList function_return 0 Move Customer_DD to hoCustomerDD // namespaceURI of in and out xml doc Move "http://www.dataacess.com/Test/CustomerList" to sNs // this will be our return document Get Create U_cXmlDomDocument to hoRetXml Get CreateDocumentElementNS of hoRetXml sNs "CustomerList" to hoRetRoot // go through node list looking for customers to delete Get DocumentElement of CustomerList to hoRoot Get ChildElementNS of hoRoot sNs "Customer" to hoCust While hoCust // if attribute "Delete" is "Y" we will delete it Get AttributeValue Of hoCust "Delete" To sDel Move (sDel="Y") to bDelete If (bDelete) Begin // attempt to delete customer Get ChildElementValueNS Of hoCust sNs "Number" To sNumber Send Clear of hoCustomerDD Move sNumber to Customer.Customer_Number Send Find of hoCustomerDD eq 1 If (found) Begin // This is commented out because this is a test. We will // remove the customer from the XML list but not from the // data table. This allows the sample to be run over and over. //Send Request_delete of hoCustomerDD //If (err) begin // Move False to bDelete //end End End // if not deleted, add the customer node the return document If not bDelete begin Get CloneNode of hoCust true to hoRetCust // clone node and all children Get AppendNode of hoRetRoot hoRetCust to hoRetCust // append to return doc Send destroy of hoRetCust End // Get NextElementNS of hoCust sNs "Customer" to hoCust Loop // note that both the passed xml document and the return document will get // destroyed automatically by the web-service handler Function_Return hoRetXML End_Function End_Object // oCustXML