Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

How to get the reason for invalid XML

avatar
Expert Contributor

When using the ValidateXML processor with an XSD, how do I capture the reason for the invalid XML so I can troubleshoot instances when the incoming XML is invalid?  

 

Unfortunately I don't have access to a validation tool in the environment where NiFi is running so I need the feedback from the ValidateXML processor.

 

I appreciate the help.    

1 ACCEPTED SOLUTION

avatar

In this case I would suggest you write custom code through ExecuteScript processor to see if you can retrieve such error message. Not sure what else you can do. sorry

View solution in original post

8 REPLIES 8

avatar

The ValidateXML processor will write the error to the attribute "validatexml.invalid.error". Check for that attribute when the flowfile is directed to the invalid relationship. Hope that helps

avatar
Expert Contributor

All that attribute reports is "Validation failed".  I need to know why it failed and at what line number in the flow file it failed.  Is it possible to get this information?

avatar

In this case I would suggest you write custom code through ExecuteScript processor to see if you can retrieve such error message. Not sure what else you can do. sorry

avatar
Expert Contributor

OK, thank you for verifying this for me.

avatar
New Contributor

Hi @ChuckE using NiFi 1.15.2 seems to add the error detail in the "validatexml.invalid.error" attribute.
For example --> "cvc-minLength-valid: Value '' with length = '0' is not facet-valid with respect to minLength '1' for type 'HotelCode"

This seems to be an issue starting from NiFi 1.16.3, maybe a bug?
You can use NiFi 1.15.2 or custom code as @SAMSAL suggested.

avatar
Expert Contributor

That would be nice, but unfortunately v.1.16.x  doesn't incorporate this feature and all you get is a generic message: "Validation Failed".  In the end I just resorted to downloading the problem flowfile from the queue, and then used xmllint to run a validation, which gave me the answer instantly.  But it would be really nice if the developers put the error message back into the "validatexml.invalid.error" attribute in v.1.16.x

avatar
New Contributor

Hi all

Sorry I'm new to nifi

Anyone found a better way to output the xsd error details? 

Not sure how to use script to output the error details, please share some ideas. Thanks

avatar
Expert Contributor

Are you referring to validation failures?  If this is what you are referring to then the answer is, you can't.  If you get failures then you'll need to queue the failures up and validate them manually to see why they failed.  I use xmllint.  For example: 

xmllint --noout --schema my_data_schema.xsd my_data.xml