Search code examples
xmlapache-nifiwell-formed

Prove XML is Well Formed on Nifi


I'm trying to prove my XML is well formed on Nifi.

I already validate it against some schema, but sometimes I do not have a schema and so wish to just confirm it is well formed. However all the XML processers seem to require a schema or such and don't just show it being well formed.

Can anyone privde some assitance? Many Thanks


Solution

  • To add to kjhughes's answer (specific to NiFi), if you always know the root tag (let's call it "root"), you can use the XSD mentioned in this SO post with the ValidateXml processor.

    If you don't know the root tag, you can use ExecuteGroovyScript with the "Failure strategy" property set to "transfer to failure" and "Script Body" set to the following script:

    def flowFile = session.get()
    if(!flowFile) return
    InputStream i = flowFile.read()
    new XmlSlurper().parse(i)
    i.close()
    REL_SUCCESS << flowFile