Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]
Created 07-28-2022 11:13 PM
When using the XMLReader service, how do you retain the outermost parent element of an XML document so when I convert it to JSON I have the outermost element in the JSON version too?
For example, given the following XML document how do I capture the "<a>" element rather than just the "<b>" element?
<a>
<b>45</b>
</a>
What I want:
{"a": {"b":45}}
What I get:
{"b":45}
Created 08-02-2022 10:20 PM
@ChuckE ,
You can use a JoltTransformRecord processor to perform the conversion to JSON and, at the same time, add the root node back to it.
The JOLT specification I used is this:
{
"*": "a.&"
}
Cheers,
André
Created 08-03-2022 10:13 AM
I've since discovered a super easy way to resolve this. Simply using the XMLRecordSetWriter does EXACTLY what I was looking for.
Created 08-03-2022 07:59 PM
I create an XMLRecordSetWriter in the Controller Services, then using a ConvertRecord processor I'm able to read the xml record and then immediately write it out with a new root tag, which I can then pass to my next processor. I discovered this when I was reading the documentation for the XMLRecordSetWriter. Very first line in the documentation. 😃
Created 08-03-2022 07:33 PM
Ahh! Good catch, @ChuckE !! So simple!