Writing an app in adobe flex 3 getting data from http://drupal.org/project/services module (and amfphp)
Get data from services module as array calling taxonomy_select_nodes
Using simpleXMLEncoder.encodeValue() to convert result array into XML
resulting XML is incorrectly formatted:
<root>
<item>
<some nodes>
<taxonomy>
<25>
<description/>
<name>who</name>
<tid>25</tid>
<vid>5</vid>
<weight>0</weight>
</25>
<4>
<description/>
<name>Institutional Changes</name>
<tid>4</tid>
<vid>1</vid>
<weight>-10</weight>
</4>
</taxonomy>
</some nodes>
</item>
</root>
"<25>" is an actual tid
"<4>" is an actual vid
The 4 and 25 are already included in the XML. These nodes should be named the same word/identifier so that they can be referenced programmatically.
This is invalid XML structure as these nodes should have a common identifier.
We are thinking we should submit a patch to taxonomy.module to correct this problem
But, as far we can see, this would actually require an extensive rewrite of the whole taxonomy.module
We may end up doing this locally, but would there be interest in us submitting this patch for actual inclusion in drupal core itself?
Comments
Comment #1
SamRose commented(correction of above both 25 and 4 are tids)
Comment #2
dave reidWell, since Drupal doesn't format the data from taxonomy_select_nodes as XML, this should be an issue for the services module, or a different module if the services maintainer determines so.
Comment #3
SamRose commentedNothing formats the Drupal data as XML.
*but* the *way* that Taxonomy module is written causes what I am talking about above.
it is my belief that the need to be able to export the array and have it formatted as XMl was not considered when the taxonomy.module was created.
Services module really has nothing to do with it. Services simply *uses* taxonomy_select_nodes to get the array
The real problem lies in the poorly structured way that the array that is access by taxonomy_select_nodes is created in the first place. I believe the problem lies with http://api.drupal.org/api/function/taxonomy_get_term/5
In Drupal, why does the array that taxonomy_select_nodes returns repeat the tid twice in 2 different ways? There doesn't seem to be any good reason for it that I can see. If it did not work this way, then you could export this array and transform it into xml in various other scripting languages and do things with the data. but, this unnecessary repetition *breaks* the ability to do this.
It just doesn't make sense to me why this happens in this way.
Comment #4
dave reidWell, if the XML needs to be fixed, there probably needs to be some kind of work around in the Services module. If the taxonomy_get_term needs fixing, let's file a separate Drupal issue for that.
Comment #5
paulbhartzog commentedEven in a returned array, the "4" and the "25" should be replaced by the term "term" since they are repeated items and should be identified using a noun that says what they are and what their internal array elements are properties of. They are term properties (like 'tid') so the correct identifier for each of those portions of the array is "term".
hope that helps
Comment #6
dman commentedIs better XML I think?
By choice I'd be putting the tid,vid as attributes, but that's not important.
Comment #7
marcingy commentedThe flash application can manipulate the data before rendering. If you wish to have this functionality you will need to role a patch for D7 to change the format of the data returned from the taxonomy module.
Comment #8
dman commentedFlash can probably not do anything with that 'XML' if it's using any valid libraries.
The actual output
should not be parsed - numbers are not legal XML element names.
The XML-like output should at least be valid so that other services can read it. Any process that does currently successfully parse that input is therefore non-compliant, according the XMLs "do not be liberal with what you accept" rule.
Yeah, I'll look at a patch if I ever start using services ... but I'm just passing on some XML standards advice...
Comment #9
marcingy commentedWith regards the patch to Drupal I feel that is the best approach. The patch will obviously go through the normal review processes. If you submit a patch and you let me know the issue number I will be more than glad to help review it.