#native_company# #native_desc#
#native_cta#

PHP, XML, XSL, XPATH and Web Services Page 3

By Mashooq Badar
on May 6, 2004

The following are some of the methods exposed:
getUser(user_id):User Get the user element given the user id
findUsers(user):UserList Get a list of user elements given the criteria in the user element. Here the user element would be partially populated with the fields we need to match in the “where” clause of our query.
insertUser(user):boolean Insert new user. Here the user details are provided in the user element
updateUser(user):boolean Update the specified user
deleteUser(user_id):boolean Delete the specified user
findMediaByUser(user_id):MediaList Find Media that is owned by the specified user
The User and UserList XML elements are specified by the following graphical representation of an XML schema:
XML schema
The Content Engine Implementation
There are two main challenges when implementing each function of the Content Engine:
  1. How to transform the resultset into XML in a generic manner?
  2. How to access the attribute values from the XML coming in (i.e. in find, insert and update functions).
Generic transformation of query results to XML
In PHP (and no doubt other languages) each resultset, as well as containing the result data, contains the names of the attributes returned. This allows us to generically generate XML from a resultset without having to “hardcode” any XML tags for the attributes, however for each row we have to define the enclosing XML tags. The following are the interface definitions of two helper functions used to return an XML element and an XML element list given the query to execute and the connection to execute it on:

<?php

/* 
Returns the first rows as elements within their column-names as the tag-names
The elements are enclosed in the specified $elemName
 */
function get_element($elemName$conn$query
{

}

/*
Returns the first rows as elements enclosed within their column-names as the tag-names
The elements are enclosed in the specified $elemName. The full list is enclosed in the 
specified $listName
*/
function get_element_list($listName$elemName$conn$query
{
        
}
?>

1
|
2
|
3
|
4
|
5
|
6
|
7