My simple flow:
The input XML:
The output JSON:
Several questions arise:
@David Sargrad , I faced the same issue and I believe that the nested structure of your XML is causing inferredSchema to fill null in those attributes. I came across this post, it suggested using a XSLT file to transform the XML directly to JSON. The inferred Schema works great for flat XML files.
You might want to give it a try or you can manually define a schema for the file you want to convert.
Here is how you can use the XSLT to transform the XML.
Configuration of TransformXML processor
Save the XSLT file and add the path to the file at XSLT file name
Hi @Sumit Das
Thanks for your response. I came to the same conclusion. I have indeed used XSLT before along with TransformXML. I was hoping that the new capability with XMLReader would give me an alternative option.
Given the current state of the inference capability, I think that you are right.
Thanks again for taking the time to respond.
I did write an issue on the NIFI issue board: https://issues.apache.org/jira/browse/NIFI-6241. Hopefully this will get some attention.
@David Sargrad , Would you mind sharing the source of your XML? I want to see if I missed something. Also, I could not find a way to have a look at the schema. Write Schema to attribute is disabled on inferSchema. Even InferavroSchema processor supports CSV and JSON only at the moment. Please share if you find a way to look at the inferred schema in future.
If it is a bug, lets hope it gets fixed soon.
Please see the template i added in my comment above.. it has the source generator that you need (Test_Convert_Record_2.xml)
I fiddled with the XML and I found that the issue is having data in form of XML attributes. For example if the longitude and latitude data is in this format, you get the desired output.
Seems like there is some issue in the XMLReader. I upvoted your JIRA issue. Lets wait and see. Thanks for your response.