With this data (which is generated by services itself), the values of the array "hej" is not parsed properly.
<?xml version="1.0" encoding="utf-8"?>
<node>
<type>article</type>
<title>lala</title>
<hej is_array="true">
<item>1</item>
<item>23</item>
<item><bla>4</bla></item>
<item>5</item>
<item>6</item>
<item>7</item>
<item>8</item>
<item>9</item>
</hej>
</node>
The result is:
array (
'type' => 'article',
'title' => 'lala',
'hej' =>
array (
0 => NULL,
1 => NULL,
2 =>
array (
'bla' => '4',
),
3 => NULL,
4 => NULL,
5 => NULL,
6 => NULL,
7 => NULL,
),
)
I.e. the values of the "hej" array are all NULL.
Comments
Comment #1
esbenvb commentedHere's a patch.
IMPORTANT: When porting the patch to the GIT repo, follow the instructions here:
http://drupal.org/user/989064
Comment #2
marcingy commentedI not reviewed the code but the patch does not meet drupals coding standards.
Comment #3
esbenvb commentedNo shit sherlock :)
None of the code in the Services module meets the Drupal Coding standards. To make the patch and the new code look most readable in the context of the RESTServer.inc file, i chose to use the same indentation method as already used in the file - if I had used proper indentation, it would have looked like a mess next to the other code and probably someone else would have complained about that...
Comment #4
esbenvb commentedBumped status
Comment #5
marcingy commentedlol, I have just looked at the code and this function sucks for standards so yeah lets leave that for a different issue! So I am wondering if we actually want to keep the call the function in a recursive manner. So atm we do
Why not
What you have looks good but continuing to following a core pattern if possible would be nice.
Comment #6
esbenvb commentedThis patch only affects the lines of code INSIDE your for-loop - it handles the case where the array child elements are just a text string. How you handle the for loop outside the code of my patch has nothing to do with that...
Comment #7
marcingy commentedWhat I am say is don't treat your element as an exception and instead fix the outer loop so as recursion remains in all cases to grab child elements.
Comment #8
esbenvb commentedI'll leave the decision up to you, on how to solve this - I know that there are several ways to achieve the same and I just suggested one :)
Anyway, If you want to dramatically change to how Services handles XML, I think it would be best to just treat numeric arrays like a series of elements with the same name.
Like
Which should be the XML representation of
Comment #9
gielfeldt commentedHere's an updated patch for 7.x-3.5
Comment #10
ygerasimov commentedComment #11
kylebrowning commentedFIxed in dev, thanks
Comment #13
apanag commentedSorry for reopening the current task, but the patch didn't work me. I tried both XML in comments #1 and #8, apart from my XMLs, but still I was getting a NULL value.
I did my tests with version 3.x-dev. The following code however worked for me:
Let me know, if you need more informations.
Comment #14
apanag commentedPatch attached with the above code.
Thank you!
Comment #15
kylebrowning commentedFixed, thanks.
Comment #17
klokie commentedHi, this recent change has broken compatibility with our incoming XML. Now instead of parsing the content child node
<value/>, the array element contains only the whitespace content of the node (e.g. "\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t "). Incoming XML looks like this:We've been using this format for a while now. Is this still the correct format for XML requests? Thanks.
Comment #18
klokie commentedComment #19
bcweaver commentedThis commit included in 7.x-3.6 is breaking my site.. where my resource's update callback had been getting a nice array of entity objects, now it receives an array of empty/whitespace-only values.
Reverting this block in servers/rest_server/includes/ServicesParser.inc starting on line 67:
back to:
solves my problem.
Comment #20
kylebrowning commentedLooks like our test coverage of XML is abysmal.
I don't have any xml cases setup, any chance I can get some help to resolve this issue?
Im happy to review patches, if nobody can help, ill move towards getting something setup next week.
In the meantime, I would suggest reverting that commit for yourself and placing using that instead of a release.
git revert f5f16455805b5d16a268b1139d81376e91ba1946Comment #21
akroplas commentedSimple patch:
replace
elseif (is_object($item)) {in
foreach($child->children() as $item)with
elseif (is_object($item) && ($item->count() == 0)) {It checks whether $item has children (for example
<value>).Also I've add
$array[$child->getName()] = array();to avoid PHP Notice: Undefined indexComment #22
akroplas commentedComment #23
kylebrowning commented21: services-rest_server_parse_xml_with_arrays-1912842-20.patch queued for re-testing.
Comment #24
kylebrowning commented