Skip to main content
ChuckE
Gold ⭐️
May 25, 2022
Solved

How to get the reason for invalid XML

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.    

SAMSAL
SAMSALAnswer
Platinum ⭐️⭐️⭐️
May 25, 2022

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

8 replies

SAMSAL
Platinum ⭐️⭐️⭐️
May 25, 2022

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

Translate
ChuckE
ChuckEAuthor
Gold ⭐️
May 25, 2022

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?

Translate
SAMSAL
SAMSALAnswer
Platinum ⭐️⭐️⭐️
May 25, 2022

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

Translate
ChuckE
ChuckEAuthor
Gold ⭐️
May 25, 2022

OK, thank you for verifying this for me.

Translate
Eduu
Gold ⭐️
July 25, 2022

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.

Translate
ChuckE
ChuckEAuthor
Gold ⭐️
July 27, 2022

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

Translate
Kevler
Silver ⭐️
August 5, 2023

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

Translate
ChuckE
ChuckEAuthor
Gold ⭐️
August 7, 2023

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

 

 

Translate