diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php
index 823f8d2d6..c4b693a0c 100644
--- a/cake/libs/model/model.php
+++ b/cake/libs/model/model.php
@@ -831,7 +831,12 @@ class Model extends Object {
return;
}
if (is_object($one)) {
- $one = Set::reverse($one);
+ if ($one instanceof SimpleXMLElement || $one instanceof DOMNode) {
+ App::import('Core', 'Xml');
+ $one = $this->_normalizeXmlData(Xml::toArray($one));
+ } else {
+ $one = Set::reverse($one);
+ }
}
if (is_array($one)) {
@@ -868,6 +873,26 @@ class Model extends Object {
return $data;
}
+/**
+ * Normalize Xml::toArray() to use in Model::save()
+ *
+ * @param array $xml XML as array
+ * @return array
+ */
+ protected function _normalizeXmlData(array $xml) {
+ $return = array();
+ foreach ($xml as $key => $value) {
+ if (is_array($value)) {
+ $return[Inflector::camelize($key)] = $this->_normalizeXmlData($value);
+ } elseif ($key[0] === '@') {
+ $return[substr($key, 1)] = $value;
+ } else {
+ $return[$key] = $value;
+ }
+ }
+ return $return;
+ }
+
/**
* Deconstructs a complex data type (array or object) into a single field value.
*
diff --git a/cake/tests/cases/libs/model/model_write.test.php b/cake/tests/cases/libs/model/model_write.test.php
index fcf7c8e8f..4693bf30a 100644
--- a/cake/tests/cases/libs/model/model_write.test.php
+++ b/cake/tests/cases/libs/model/model_write.test.php
@@ -1019,12 +1019,20 @@ class ModelWriteTest extends BaseModelTest {
App::import('Core', 'Xml');
$Article = new Article();
- $Article->save(new Xml(''));
- $result = $Article->save(new Xml(''));
+ $result = $Article->save(Xml::build(''));
$this->assertFalse(empty($result));
-
$results = $Article->find(array('Article.title' => 'test xml'));
$this->assertFalse(empty($results));
+
+ $result = $Article->save(Xml::build('
passed to a flex app. I have the following model association:
ServiceDay->(hasMany)ServiceTi me->(hasMany)ServiceTimePrice. So what
the current output from my findall is something like this example:
Array(
[0] => Array(",
- 'guid' => array('isPermaLink' => 'true', 'value' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f'),
+ 'guid' => array('@isPermaLink' => 'true', '@' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f'),
'author' => 'bmil...@gmail.com(bpscrugs)',
'pubDate' => 'Fri, 28 Dec 2007 00:44:14 UT',
),
@@ -2750,7 +2750,7 @@ class SetTest extends CakeTestCase {
'title' => 'Re: share views between actions?',
'link' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8',
'description' => 'Then perhaps you might do us all a favour and refrain from replying to
things you do not understand. That goes especially for asinine comments.
Indeed.
To sum up:
No comment.
In my day, a simple "RTFM" would suffice. I\'ll keep in mind to ignore any
further responses from you.
You (and I) were referring to the *online documentation*, not other',
- 'guid' => array('isPermaLink' => 'true', 'value' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8'),
+ 'guid' => array('@isPermaLink' => 'true', '@' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8'),
'author' => 'subtropolis.z...@gmail.com(subtropolis zijn)',
'pubDate' => 'Fri, 28 Dec 2007 00:45:01 UT'
)
@@ -2762,7 +2762,7 @@ class SetTest extends CakeTestCase {
$xml = Xml::build($string);
$result = Set::reverse($xml);
- $expected = array('data' => array('post' => array('title' => 'Title of this post', 'description' => 'cool')));
+ $expected = array('data' => array('post' => array('@title' => 'Title of this post', '@description' => 'cool')));
$this->assertEqual($result, $expected);
$xml = Xml::build('
passed to a flex app. I have the following model association:
ServiceDay->(hasMany)ServiceTi me->(hasMany)ServiceTimePrice. So what
the current output from my findall is something like this example:
Array(
[0] => Array(",
- 'creator' => 'cakephp',
+ 'dc:creator' => 'cakephp',
'category' => array('cakephp', 'model'),
- 'guid' => array('isPermaLink' => 'true', 'value' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f'),
+ 'guid' => array('@isPermaLink' => 'true', '@' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f'),
'author' => 'bmil...@gmail.com(bpscrugs)',
'pubDate' => 'Fri, 28 Dec 2007 00:44:14 UT',
),
@@ -2862,9 +2862,9 @@ class SetTest extends CakeTestCase {
'title' => 'Re: share views between actions?',
'link' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8',
'description' => 'Then perhaps you might do us all a favour and refrain from replying to
things you do not understand. That goes especially for asinine comments.
Indeed.
To sum up:
No comment.
In my day, a simple "RTFM" would suffice. I\'ll keep in mind to ignore any
further responses from you.
You (and I) were referring to the *online documentation*, not other',
- 'creator' => 'cakephp',
+ 'dc:creator' => 'cakephp',
'category' => array('cakephp', 'model'),
- 'guid' => array('isPermaLink' => 'true', 'value' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8'),
+ 'guid' => array('@isPermaLink' => 'true', '@' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8'),
'author' => 'subtropolis.z...@gmail.com(subtropolis zijn)',
'pubDate' => 'Fri, 28 Dec 2007 00:45:01 UT'
)
@@ -2901,8 +2901,8 @@ class SetTest extends CakeTestCase {
$expected = array('XRDS' => array(
'XRD' => array(
array(
- 'id' => 'oauth',
- 'version' => '2.0',
+ '@xml:id' => 'oauth',
+ '@version' => '2.0',
'Type' => 'xri://$xrds*simple',
'Expires' => '2008-04-13T07:34:58Z',
'Service' => array(
@@ -2913,21 +2913,21 @@ class SetTest extends CakeTestCase {
),
'URI' => array(
array(
- 'value' => 'https://ma.gnolia.com/oauth/authorize',
- 'priority' => '10',
+ '@' => 'https://ma.gnolia.com/oauth/authorize',
+ '@priority' => '10',
),
array(
- 'value' => 'http://ma.gnolia.com/oauth/authorize',
- 'priority' => '20'
+ '@' => 'http://ma.gnolia.com/oauth/authorize',
+ '@priority' => '20'
)
)
)
),
array(
- 'version' => '2.0',
+ '@version' => '2.0',
'Type' => 'xri://$xrds*simple',
'Service' => array(
- 'priority' => '10',
+ '@priority' => '10',
'Type' => 'http://oauth.net/discovery/1.0',
'URI' => '#oauth'
)