- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Preserving the parent element in XML document with XMLReader
- Labels:
-
Apache NiFi
Created ‎07-28-2022 11:13 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@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é
Was your question answered? Please take some time to click on "Accept as Solution" below this post.
If you find a reply useful, say thanks by clicking on the thumbs up button.
Created ‎08-03-2022 10:13 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ahh! Good catch, @ChuckE !! So simple!
Was your question answered? Please take some time to click on "Accept as Solution" below this post.
If you find a reply useful, say thanks by clicking on the thumbs up button.

- « Previous
-
- 1
- 2
- Next »