Need assistance in Templates for nested/recursive data

Hi,
I am trying to use template for nested data parsing. My scenario is ‘category’ will have ‘subcategory’ and ‘subcategory’ can have nested ‘category’ tree and so on repeatedly. I have configured mapping like,

<Mapping element="category"  templateId="myTemplate" xmlFields="name" cloverFields="categoryName">
	<Mapping element="subCategory" 
		xmlFields="name"
		cloverFields="subCategoryName">
                <Mapping templateRef="myTemplate"></Mapping>
        </Mapping> 
</Mapping>

With the above mapping, templateRef is parsing only ‘subcategory->category’ elements, but not able to parse ‘subcategory->category->subcategory’ elements.
ex.,

"category" : {
	"name" : "cat1",
	"subCategory" : {
		"name" : "subcat1",
		"category" : {
			"name" : "cat2",
			"subCategory" : {
				"name" : "subcat2"
			}
		}
	}
}

mapping file had parsed only ‘cat1’, ‘subcat1’ & ‘cat2’ elements. ‘subcat2’ is not parsed. Please suggest solution.

Hi,

Could you please specify what you expect on output?
Also is there any chance to obtain these categories with some unique Ids?

Thanks,

Hi, I was trying to convert above json to xml, with expected output is


<category>
	<name>cat1</name>
	<subcategory>
		<name>subcat1</name>
		<category>
			<name>cat2</name>
			<subCategory>
				<name>subcat2</name>
			</subCategory>
		</category>
	</subcategory>
</category>

Categories does not have unique ids, but can be combined with parent category name to make it unique.

Hi Madan,

usually this would be done by two our components:

Unfortunately there is an issue in XMLWriter that does not allow us to write recursive structures into XML. For more information, please refer to: https://bug.javlin.eu/browse/CLO-3952

A workaround for this issue might be replacing JSON structure with XML structure using regular expressions. I have created an example for you, so that you can see how that might be handled in CTL language.

Hope this helps.

Thank you very much for you time and support. Will give a try with your example.