• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Multilevel structure to XML

New Here ,
Nov 22, 2007 Nov 22, 2007

Copy link to clipboard

Copied

Hi,

I have a multilevel structure that looks like that :
a = structNew()
a.a.a.a = apple
a.a.a.b = banana
a.a.b.a = potato
a.b = beef

What would be the best way of converting that structure in an XML document that would look like the following attached code ?

Any suggestion ? The structure isn't always 4-levels deep. Sometimes it can be 3, 4, 8, 2...

I thought I would just loop recursively over my structure : calling a method that would check if the item is a struct and if so create a new XML node inside the XML node being processed or else just put the value in node currently being open, then return the result back to the calling method... and so on.

Is there any sort of code snippet that may convert a multilevel structure to an XML document ? All examples I've found so far only deals with one level.

Thanks in advance,

Patrick
TOPICS
Advanced techniques

Views

265

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 30, 2007 Nov 30, 2007

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 01, 2007 Dec 01, 2007

Copy link to clipboard

Copied

LATEST
Here's the code:

For our purpose we had to deal with orderlines and some form structure up to 8 levels deep. If your structures names are all uniques, you can remove the part in the CFC that checks for the iteration indicator (___i) in a structure name.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 01, 2007 Dec 01, 2007

Copy link to clipboard

Copied

Thanks, I already came accross that code but unfortunately it does process only the first level of a structure :
form.author
form.book_title
form.nb_book_pages

And I needed :
form.author.firstname
form.author.lastname
form.book.title
form.book.pages
etc...

But I found a solution ! I did it through a recursive function inside a CFC... I'll post the code soon, I don't have it at hand right now.

Patrick

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation