I have a plugin to override web_services plugin and want to output my API result in XML format in addition to JSON (default) and CSV. I added below code to mod/my_plugin/views/xml/api/output.php file
$result = $vars['result'];
$export = $result->export();
echo serialize_object_to_xml($export);
function serialize_object_to_xml($data) {
$serializer_options = array ( 'addDecl' => FALSE, 'encoding' => 'UTF-8', 'indent' => ' ');
$Serializer = new XML_Serializer($serializer_options);
$Serializer->serialize($data);
return $Serializer->getSerializedData();
}
I use PEAR-1.10.10, XML_Serializer-0.21.0, XML_Parser-1.3.8, and XML_Util-1.4.4 to serialize data to XML format. I put these libraries in mod/my_plugin/vendors directory and added below lines in init function inside my plugin
set_include_path(elgg_get_plugins_path() . "my_plugin/vendors/XML_Serializer-0.21.0" . PATH_SEPARATOR . get_include_path() );
set_include_path(elgg_get_plugins_path() . "my_plugin/vendors/PEAR-1.10.10" . PATH_SEPARATOR . get_include_path() );
set_include_path(elgg_get_plugins_path() . "my_plugin/vendors/XML_Util-1.4.4" . PATH_SEPARATOR . get_include_path() );
set_include_path(elgg_get_plugins_path() . "my_plugin/vendors/XML_Parser-1.3.8" . PATH_SEPARATOR . get_include_path() );
Configurations above works with my Elgg2.3* site BUT not with Elgg3.3.2. My server currently uses PHP7.3.16.
Did I miss anything on my configurations for Elgg3.3.2?
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by Raül Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
- Jerome Bakker@jeabakker

Jerome Bakker - 0 likes
- seri_ng@seri_ng

seri_ng - 0 likes
- seri_ng@seri_ng

seri_ng - 0 likes
You must log in to post replies.Have a look at the data_Views plugin. It provides the xml output for the webservices https://github.com/Elgg/data_views
Thanks Jerome! I am going to check it out.
Now I got it to work. What I did was adding mod/my_plugin/views/xml/page/default.php file in addition to my existing code. Below is the code I copied from data_views plugin and put it in default.php file.
header('Content-Type: text/xml');
echo "<?xml version='1.0' encoding='UTF-8' ?>\n";
echo $vars['body'];
Thanks again Jerome!