Created
October 18, 2011 23:34
-
-
Save cotto/1297070 to your computer and use it in GitHub Desktop.
xml request parser for rest server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/servers/rest_server/includes/RESTServer.inc b/servers/rest_server/includes/RESTServer.inc | |
index 63528bc..74bc6b3 100755 | |
--- a/servers/rest_server/includes/RESTServer.inc | |
+++ b/servers/rest_server/includes/RESTServer.inc | |
@@ -455,6 +455,26 @@ class RESTServer { | |
return self::contentFromStream($handle); | |
} | |
+ public static function parseXML($handle) { | |
+ $old_error_state = libxml_use_internal_errors(1); | |
+ libxml_clear_errors(); | |
+ $xml_data = simplexml_load_string(self::contentFromStream($handle)); | |
+ | |
+ if (!$xml_data) { | |
+ $message = ''; | |
+ $errors = libxml_get_errors(); | |
+ foreach ($errors as $error) { | |
+ $message .= 'ERROR' . t('Line @line, Col @column: @message', array('@line' => $error->line, '@column' => $error->column, '@message' => $error->message)) . "\n\n"; | |
+ } | |
+ libxml_clear_errors(); | |
+ libxml_use_internal_errors($old_error_state); | |
+ services_error($message, 406); | |
+ } | |
+ libxml_use_internal_errors($old_error_state); | |
+ | |
+ return (array) $xml_data; | |
+ } | |
+ | |
public static function parseJSON($handle) { | |
return json_decode(self::contentFromStream($handle), TRUE); | |
} | |
@@ -567,4 +587,4 @@ class RESTServer { | |
return $action; | |
} | |
} | |
-} | |
\ No newline at end of file | |
+} | |
diff --git a/servers/rest_server/rest_server.module b/servers/rest_server/rest_server.module | |
index 100d022..d27020d 100755 | |
--- a/servers/rest_server/rest_server.module | |
+++ b/servers/rest_server/rest_server.module | |
@@ -65,6 +65,7 @@ function rest_server_request_parsers() { | |
'application/json' => 'RESTServer::parseJSON', | |
'application/vnd.php.serialized' => 'RESTServer::parsePHP', | |
'multipart/form-data' => 'RESTServer::parseFile', | |
+ 'application/xml' => 'RESTServer::parseXML', | |
); | |
drupal_alter('rest_server_request_parsers', $parsers); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment