Synthoid / ExportSheetData

Add-on for Google Sheets that allows sheets to be exported as JSON or XML.
MIT License
236 stars 46 forks source link

Nested XML + Multiple identically-named fields #75

Open deek419 opened 5 years ago

deek419 commented 5 years ago

First Chris/Synthoid, thank you, amazing work! I'm trying to output XML for input into an existing food / recipe app. Here's a subset of the fields:

Fields: Title | Description | Servings (quantity=n, unit="name") | Ingredient (name="name", quantity=n) | Ingredient (name="name", quantity=n)

Required output: <?xml version="1.0"?>

Turkey Dinner Keep the family sleepy.

First issue: I've fiddled and read through the documentation and examples, and it appears that nesting is only available for JSON ... is that still true?

Second issue: per my example, XML must output to show multiple identically-named ... fields -- max 10. Is this possible?

I have several hundred recipes to convert, so a timely solution here would be amazing. Thank you!

Synthoid commented 5 years ago

Thanks for using ESD! Unfortunately, nested elements are still limited to JSON currently. Adding support for XML nested elements will require a complete rewrite of how XML is exported, which is one of the reasons I've held off on it. When you say "XML must output to show multiple identically-named ... fields" are you talking about multiple elements with the same name? For example:

<data>
  <element>Earth</element>
  <element>Wind</element>
  <element>Fire</element>
  <element>Water</element>
</data>
deek419 commented 5 years ago

Thanks Chris. Unfortunate for me that XML won't be ready for awhile. Here's what I mean by identically named fields:

<recipe>
   <ingredient name="abc" quantity=3 unit="cups"></ingredient>
   <ingredient name="def" quantity=2 unit="tbsp"></ingredient>
</recipe>
Synthoid commented 5 years ago

Sorry for the inconvenience. The rewrite for JSON took the better part of a month. XML will probably take at least as long, and would need to be heavily tested to make sure it is usable without being too confusing.

As for the identically named fields, you should be able to do that by making each ingredient it's own row in the sheet. If you'd like to have inner text for each field (text between the open and close tags) you should preface a field with "IT_" and enable "Inner text prefix" in the advanced section.

deek419 commented 5 years ago

Hi Chris, I can appreciate the amount of work it has taken to get the app to this point -- very impressive.

I did fiddle with the IT_ option (and some others), but maybe I didn't enable "Inner text prefix" or otherwise missed a configuration step. Can you take a quick look at the slightly more detailed schema below (which the recipe app needs as input), and tell me how close ESD should be able to get me? (So to clarify, my sheet would have several hundred rows, one recipe per row, to be converted into this kind of schema).

If ESD isn't quite there yet, are there any other XML transformation tools that might work for me? There may be something in Excel, though my quick looks suggests it's pretty kludgy.

Thanks again. Derrick

<?xml version="1.0"?>
<recipes>
<recipe>
<title>Veggie Dinner</title>
<description>Make your family sleepy this Thanksgiving.</description>
<servings quantity="16" unit="people"></servings>
<ingredient name="Turkey" quantity="2" unit="cups"></ingredient>
<ingredient name="Carrots" quantity="1.5" unit="cups"></ingredient>
</recipe>
</recipes>
Synthoid commented 5 years ago

Hmm... The only thing I think may be troublesome would be the child elements with attributes (the "servings" and "ingredient" elements). Did you write the tool that imports the data, or is it a third party tool?

As far as other XML exporting options, I'm sure there is an Excel plugin that can do what you want, but I'm not sure how easy it would be to use, nor if it is available for free or not. I don't think there is another JSON/XML exporter add-on for Google Sheets (I probably wouldn't have made ESD if there was) but it's possible a new one has been made since the last time I looked.

If you share a sample sheet of your data, I can see what I can do to get the format as close as possible to your desired output.

deek419 commented 5 years ago

Looks like I can't share a google sheet here, so I've converted it to excel (attached). Thanks for taking a closer look! -Derrick

xml-test.xlsx

Synthoid commented 5 years ago

Messed around with the sample sheet a little and this was the best I could do:

<?xml version="1.0"?>
<recipes>
  <recipe>
    <title>veggie dinner</title>
    <description>veggie description</description>
    <_servings_quantity>4</_servings_quantity>
    <_servings_unit>plates</_servings_unit>
    <ingredient_name_>carrot</ingredient_name_>
    <ingredient_quantity_>2</ingredient_quantity_>
    <ingredients_unit_>cups</ingredients_unit_>
    <ingredient_name_>celery</ingredient_name_>
    <ingredient_quantity_>1</ingredient_quantity_>
    <ingredients_unit_>cup</ingredients_unit_>
  </recipe>
</recipes>

Unfortunately, XML support in ESD doesn't handle more than 1 or 2 levels of elements, making your currently desired format impossible to export to. This will be the case until XML Nested Elements are implemented.

deek419 commented 5 years ago

Great of you to take a look at this for me Chris, many thanks. I'll explore some other options.

matiasdesign commented 4 years ago

@Synthoid Any estimation when the XML Nested Elements could be implemented?