Support is online

XML Combine Element Nodes #9060

Open j2UH8875Wvq4kbFS opened this topic Thursday, 03 August 2017 · 6 replies
Author

Hi
I am really confused by this and I was wondering if you could help.
I have a custom component. In each item there is a subform for "Property Features" which contains 10 text inputs for 10 property features. Upon save these are combined into 1 database cell in the following format:

{"com_propertyfeature1":"Feature 1","com_propertyfeature2":"Feature 2","com_propertyfeature3":"Feature 3","com_propertyfeature4":"Feature 4","com_propertyfeature5":"Feature 5","com_propertyfeature6":"Feature 6","com_propertyfeature7":"Feature 7","com_propertyfeature8":"Feature 8","com_propertyfeature9":"Feature 9","com_propertyfeature10":"Feature 10"}

My xml import file looks like this:

<property>
...
    <propertyFeature1>Feature 1</propertyFeature1>
    <propertyFeature2>Feature 2</propertyFeature2>
    <propertyFeature3>Feature 3</propertyFeature3>
    ...
...</property>

My question is; how can I take the xml node elements and combine them into one database cell in the same format as the above?

Support

Hello,
You can combine your XML nodes using CSVI combine rule and by having 10 CSVI combine template fields but the problem is with the format you need to save it in your database. That is JSON encoded format and you may not be able to get it using CSVI rules. You need to create a Override file for your import and write your own custom code to read the XML nodes in the form of an array like array('com_propertyfeature1'=>'Feature 1', 'com_propertyfeature2'=>'Feature 2,'com_propertyfeature3'=>'Feature 3',........) and then json_encode the array to get the format you are looking for.

Kind regards,

Tharuna

=========================
If you use our extensions, please post a rating and a review at the Joomla! Extension Directory

Author

Hi tharuna
Thanks for your answer. I am tacking the initial import first then I will move onto the override. I have followed the CSVI combine example but it just imports nothing. Here are some screenshots of my fields and rule, do you see anything obviously wrong?

  • Screen Shot 2017-08-03 at 13.45.40.png
  • Screen Shot 2017-08-03 at 13.45.26.png
Author

Cracked it! I needed to have "propertyFeature1, propertyFeature2, propertyFeature3, propertyFeature4, propertyFeature5, propertyFeature6, propertyFeature7, propertyFeature8, propertyFeature9, propertyFeature10" as my source fields.

Support

Hello,
Glad to know you figured it out. Now you have all the field nodes value in a single field, you need to convert it into an array and insert it into database field as a JSON format.

Kind regards,

Tharuna

=========================
If you use our extensions, please post a rating and a review at the Joomla! Extension Directory

Author

Hi tharuna
Unfortunately I have another question very similar to this. I also have the following node elements in my xml file:

<property>
...
    <flags>
        <flag>Flag 1</flag>
        <flag>Flag 2</flag>
        <flag>Flag 3</flag>
        ...
    </flags>
    ...
...</property>

There can be any number of <flag> elements so I can't create a set number of fields. I also cannot edit the xml file as outlined at Process XML files. How can I combine these elements into 1 field?
I have had a look at Import XML with same node names but this doesn't seem to fit with my xml nodes.

Support

Hello,
The answer is posted in another post here.

Kind regards,

Tharuna

=========================
If you use our extensions, please post a rating and a review at the Joomla! Extension Directory

Log in to reply to this topic.