-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error should be thrown/returned if not a valid document based on given schema #33
Comments
You need to add a "ValidationEventHandler" in the chain. hth |
Hello @phax, thanks for your helping hand. I have tried:
above prints
This detail is too raw, Is there any way to process/digest this error and derive the field for which error occurs? |
Instead of I am not aware of any more "structured" way to get this information. This is how I get the errors from the XML parser - sorry. But if you find a smart way to get this in more detail, I am very interested.... |
Instead of getErrorText I suggest to use getErrorText !!! |
Haha - good catc. Sorry. Please use getErrorText only returns the error message, whereas |
Alright, thanks for the details. |
Hello @phax,
I am trying to learn UBL and used ph-ubl library to validate the Invoice XML document.
XML document is based on UBL 2.1.
Following is a sample code I have done:
I have intentionally deleted cbc:ID from the input XML file(UBL-Invoice-2.1-Example.xml).
While reading XML on first-line aDoc will be null as cbc:ID is one of the mandatory fields as per schema.
It prints in the console that:
[SAX] cvc-complex-type.2.4.a: Invalid content was found starting with element 'cbc:IssueDate'. One of '{"urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2":CustomizationID, "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2":ProfileID, "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2":ProfileExecutionID, "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2":ID}' is expected. (org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'cbc:IssueDate'. One of '{"urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2":CustomizationID, "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2":ProfileID, "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2":ProfileExecutionID, "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2":ID}' is expected.)
How to catch this error as it just prints into the console. It should throw some error or return something so we can come to know that oh yes this is missing in input. I want to handle/collect errors if any in the input document.
Please guide/correct me if I making any mistakes.
The text was updated successfully, but these errors were encountered: