Support #6311
closed
Problem with XSD Validation of a XML-file with Saxon EE in .NET
Fixed in Maintenance Release:
Description
Hello,
I hope that it is okay to ask the following question... I have tried a lot based on your sample for version 10 to C#/.NET.
The case is that I have a XML-file with at least one XSD-error in it - according to the XSD-file. But when I try to code my solution - based on your samplecode I can't return the error. It tells me that there are zero errors in the XML-file. (The code is listed at the end of this question) Maybe I have used the code wrong - Is it possible for you to say anything about this situation - how to correct this? Or is the code correct?
Furthermore I only have an evaluation version for the moment - and therefore I get an exception which tells me that I need a license. Does this mean something for reporting the XSD-error(s) - until I purchase your solution?
I have attached the files I have used for my XSD-validation solution.
I really hope that you are willing to say what I am missing or have made wrong in according to the following code so I can report the error - if it not is correctly made.
Thanks in advance.
Processor processor = new Processor(true);
processor.SetProperty("http://saxon.sf.net/feature/timing", "true");
processor.SetProperty("http://saxon.sf.net/feature/validation-warnings", "false"); //Set to true to suppress the exception
SchemaManager manager = processor.SchemaManager;
manager.XsdVersion = "1.1";
List<XmlProcessingError> xmlProcessingErrors = new List<XmlProcessingError>();
manager.SetErrorList(xmlProcessingErrors);
Uri schemaUri = new Uri("C:\\UBL-Invoice-2.1.xsd");
try
{
manager.Compile(schemaUri);
}
catch (Exception ex)
{
Console.WriteLine(ex);
Console.WriteLine("Schema compilation failed with " + manager.GetErrorList().Count + " errors");
foreach (StaticError error in manager.GetErrorList())
{
Console.WriteLine("At line " + error.LineNumber + ": " + error.Message);
}
//return;
}
// Use this to validate an instance document
SchemaValidator validator = manager.NewSchemaValidator();
XmlReaderSettings settings = new XmlReaderSettings();
settings.DtdProcessing = DtdProcessing.Ignore;
String inputFileName = new Uri("C:\\MCE-Invoice.xml").ToString();
XmlReader xmlReader = XmlReader.Create(inputFileName, settings);
validator.SetSource(xmlReader);
Console.WriteLine("Validating input file " + inputFileName);
validator.ErrorList = new List<ValidationFailure>();
XdmDestination psvi = new XdmDestination();
validator.SetDestination(psvi);
try
{
validator.Run();
}
catch (Exception ex)
{
Console.WriteLine(ex);
Console.WriteLine("Instance validation failed with " + validator.ErrorList.Count + " errors");
foreach (ValidationFailure error in validator.ErrorList)
{
Console.WriteLine("At line " + error.GetLineNumber() + ": " + error.GetMessage());
}
return;
}
Console.WriteLine("Input file is valid");
Regards Michael
Files
The XSD schema imports several others, thus if you want to make it easy to reproduce any validation failures you say you get you should consider to add all files, perhaps zipped up.
And which (other) tool gives exactly which errors (as you say there is at least one error)?
As Martin says, you need to supply the full schema so that we can attempt to reproduce the problem.
Does the problem occur if you attempt the validation from the command line using the Validate
command? That would rule out any errors in your application logic.
You report (a) a problem with the license file, and (b) that the program ran without errors. I find those difficult to reconcile. If no license file was found, the program should fail with a fatal error, rather than reporting the document as valid. (Though I would have to check carefully that this applied in Saxon 10).
There should be no problem running this with an evaluation license. If a problem was reported with the license, then this is an installation/configuration issue, not a problem with your C# code. Check the instructions for installing your license file.
Thank you for your answers.
I have tried to take advantage of all your solutions mentioned above - but it still gives me problems :-(
I have now found the version 2.1 files and I will try to attach this zipfile along with an updated XML-file.
Hope this makes sense ...
Thanks in advance for any kind of help.
Regards Michael
Furthermore I can give this link from Denmark https://www.oioubl.info/validator/default.aspx - this page is an official validation page in english - and this page has shown the error from XSD validation. I hope I can get the same error from the code...
Thanks in advance.
Regards Michael
Using, as Michael Kay had suggested, the validate.exe tool from the Saxon.NET 10.9 EE installation, I get lots of errors:
Validation error on line 789 column 21 of MCE-Invoice.xml:
FORG0001: In content of element <ContractDocumentReference>: The content model does not
allow element <Q{...ateComponents-2}Attachment> to appear as the first child. It must be
preceded by <Q{...sicComponents-2}ID>.
See http://www.w3.org/TR/xmlschema-1/#cvc-complex-type clause 2.4
Validation error on line 812 column 21 of MCE-Invoice.xml:
FORG0001: In content of element <ContractDocumentReference>: The content model does not
allow element <Q{...ateComponents-2}Attachment> to appear as the first child. It must be
preceded by <Q{...sicComponents-2}ID>.
See http://www.w3.org/TR/xmlschema-1/#cvc-complex-type clause 2.4
Validation error on line 835 column 21 of MCE-Invoice.xml:
FORG0001: In content of element <ContractDocumentReference>: The content model does not
allow element <Q{...ateComponents-2}Attachment> to appear as the first child. It must be
preceded by <Q{...sicComponents-2}ID>.
See http://www.w3.org/TR/xmlschema-1/#cvc-complex-type clause 2.4
Validation error on line 860 column 23 of MCE-Invoice.xml:
FORG0001: In content of element <Country>: The content model does not allow element
<Q{...sicComponents-2}Landekode> to appear as the first child. The following elements
would be valid here, all in namespace
urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2: IdentificationCode,
Name (or nothing).
See http://www.w3.org/TR/xmlschema-1/#cvc-complex-type clause 2.4
Validation error on line 905 column 27 of MCE-Invoice.xml:
FORG0001: In content of element <InvoiceLine>: The content model does not allow element
<Q{...ateComponents-2}OrderLineReference> to appear immediately after element
<Q{}{urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2}BillingReference>. The following elements would be valid here, all in namespace urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2: DocumentReference, TaxTotal, WithholdingTaxTotal, OriginatorParty, AllowanceCharge, Delivery, Item, PaymentTerms, BillingReference, PricingReference.
See http://www.w3.org/TR/xmlschema-1/#cvc-complex-type clause 2.4
Validation error on line 1010 column 19 of MCE-Invoice.xml:
FORG0001: Required attribute @Q{}unitCode is missing on element <Measure>
See http://www.w3.org/TR/xmlschema-1/#cvc-complex-type clause 4
Validation error on line 1021 column 19 of MCE-Invoice.xml:
FORG0001: Required attribute @Q{}unitCode is missing on element <Measure>
See http://www.w3.org/TR/xmlschema-1/#cvc-complex-type clause 4
Validation error on line 1032 column 19 of MCE-Invoice.xml:
FORG0001: Required attribute @Q{}unitCode is missing on element <Measure>
See http://www.w3.org/TR/xmlschema-1/#cvc-complex-type clause 4
Error on line 1128 column 11 of MCE-Invoice.xml:
XQDY0027 Eight validation errors were reported. First error: In content of element
<ContractDocumentReference>: The content model does not allow element
<Q{...ateComponents-2}Attachment> to appear as the first child. It must be preceded by
<Q{...sicComponents-2}ID>.
I will need to check whether and if so why the C# code you posted might fail to identify them.
With the C# code, I basically get
Validating input file
Eight validation errors were reported. First error: In content of element <ContractDocumentReference>: The content model does not allow element <Q{...ateComponents-2}Attachment> to appear as the first child. It must be preceded by <Q{...sicComponents-2}ID>.
Instance validation failed with 8 errors
At line 789: In content of element <ContractDocumentReference>: The content model does not allow element <Q{...ateComponents-2}Attachment> to appear as the first child. It must be preceded by <Q{...sicComponents-2}ID>.
At line 812: In content of element <ContractDocumentReference>: The content model does not allow element <Q{...ateComponents-2}Attachment> to appear as the first child. It must be preceded by <Q{...sicComponents-2}ID>.
At line 835: In content of element <ContractDocumentReference>: The content model does not allow element <Q{...ateComponents-2}Attachment> to appear as the first child. It must be preceded by <Q{...sicComponents-2}ID>.
At line 860: In content of element <Country>: The content model does not allow element <Q{...sicComponents-2}Landekode> to appear as the first child. The following elements would be valid here, all in namespace urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2: IdentificationCode, Name (or nothing).
At line 905: In content of element <InvoiceLine>: The content model does not allow element <Q{...ateComponents-2}OrderLineReference> to appear immediately after element <Q{}{urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2}BillingReference>. The following elements would be valid here, all in namespace urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2: DocumentReference, TaxTotal, WithholdingTaxTotal, OriginatorParty, AllowanceCharge, Delivery, Item, PaymentTerms, BillingReference, PricingReference.
At line 1010: Required attribute @Q{}unitCode is missing on element <Measure>
At line 1021: Required attribute @Q{}unitCode is missing on element <Measure>
At line 1032: Required attribute @Q{}unitCode is missing on element <Measure>
So what result do you actually get?
I have tried the validate tool but it gives no errors :-( Instead it gives me the following output:
No license file found - running with licensable features disabled
net.sf.saxon.trans.LicenseException: License file saxon-license.lic not found. Tried in file:/C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/saxon-ee-10.9/v4.0_10.9.0.0__e1fdd002d5083fe6/saxon-license.lic, C:\Program Files\Saxonica\SaxonEE10.9N/bin/saxon-license.lic, C:\Program Files\Saxonica\SaxonEE10.9N/saxon-license.lic, and classpath. A license is needed to use schema processing
at com.saxonica.config.EnterpriseConfiguration.checkLicensedFeature(EnterpriseConfiguration.java:333)
at com.saxonica.config.EnterpriseConfiguration.addSchema(EnterpriseConfiguration.java:684)
at com.saxonica.ee.schema.PreparedSchema.validate(PreparedSchema.java:1035)
at com.saxonica.ee.validate.XSIAttributeHandler.loadSchema(XSIAttributeHandler.java:398)
at com.saxonica.ee.validate.XSIAttributeHandler.processXsiSchemaLocation(XSIAttributeHandler.java:185)
at com.saxonica.ee.validate.XSIAttributeHandler.startElement(XSIAttributeHandler.java:107)
at net.sf.saxon.event.ProxyReceiver.startElement(ProxyReceiver.java:140)
at com.saxonica.ee.validate.AttributeInheritor.startElement(AttributeInheritor.java:52)
at net.sf.saxon.event.PathMaintainer.startElement(PathMaintainer.java:43)
at net.sf.saxon.event.DocumentValidator.startElement(DocumentValidator.java:54)
at net.sf.saxon.event.ReceivingContentHandler.startElement(ReceivingContentHandler.java:383)
at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:439)
at net.sf.saxon.event.Sender.send(Sender.java:169)
at net.sf.saxon.event.Sender.send(Sender.java:176)
at com.saxonica.ee.s9api.SchemaValidatorImpl.validate(SchemaValidatorImpl.java:611)
at com.saxonica.Validate.processFile(Validate.java:607)
at com.saxonica.Validate.doValidate(Validate.java:410)
at cli.Saxon.Cmd.DotNetValidate.Main(Unknown Source)
Fatal error during validation: License file saxon-license.lic not found. Tried in file:/C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/saxon-ee-10.9/v4.0_10.9.0.0__e1fdd002d5083fe6/saxon-license.lic, C:\Program Files\Saxonica\SaxonEE10.9N/bin/saxon-license.lic, C:\Program Files\Saxonica\SaxonEE10.9N/saxon-license.lic, and classpath. A license is needed to use schema processing
But when I check the file at the page https://www.oioubl.info/validator/default.aspx - I got error ...
So I unfortunately don't know what to do :-(
Any Ideas?
Thanks in advance.
Michael
As Martin says, the program is failing because your Saxon license hasn't been found. It tells you that it looked in
C:\Program Files\Saxonica\SaxonEE10.9N/bin/saxon-license.lic
among other places.
Where did you install the license file?
For the moment it is an evaluation version of Saxon 10 for .NET I have installed - later I plan to purchase Saxon. So I does not have a license yet ...
Is that a problem?
Right, for EE features like XSD validation you need a license, Saxonica provides evaluation licenses on request.
There is no "evaluation version" of the software, there is only an evaluation license which enables you to use the standard version of the software under limited conditions.
Martin Honnen wrote in #note-12:
Right, for EE features like XSD validation you need a license, Saxonica provides evaluation licenses on request.
Thank you so much for the answers.
I would like to request an evaluation license :-) if it is okay.
How long time do I have to evaluate this functionality with an evaluation license?
Regards Michael
Thank you very much :-)
But is it possible to place the licensfile and the configuration XML-file in a subdirectory in my .NET project?
And what will be needed to be changed - eg. paths for the files.
Unfortunately I can't get it to work with placing the necessary saxon licensfile and configurationfile in such a subdirectory :-(
Can you help me with this too?
Thanks in advance.
Michael
Thank you very much again :-)
I have got all to work now - so thats is very good !!!
But a last question: It seems to take 18 seconds for XLST validating a XML file - will this process be faster when I choose to purchase Saxon 10 ?
Regards Michael
I don't think your evaluation license slows anything down. So if some use of Saxon takes 18 seconds and you need help to investigate on how to improve that then you will need to show us exactly what you do to allow us to reproduce it.
Do you load any DTDs or schemas over HTTP(S)? Any chance there is an attempt to pull something of w3c servers?
When I run the code you posted earlier )compiled in Release mode, not Debug mode) with the schemas from the zip and the sample you posted on a Mac notebook in a Parallels Desktop Windows machine it takes 3.something seconds.
It seems to take 18 seconds
There are of course any number of factors that affect performance, some of them under your control, some under ours (and some neither!). For example with XSD validation complex regular expressions can be very slow to evaluate, and large finite bounds on minOccurs and maxOccurs can also be expensive. Choice of software and hardware also affects it, but usually less. The key to solving performance issues is to be extremely methodical in your investigation, drilling down one step at a time with careful measurement along the way. If you have a hunch (like, perhaps it's the Saxon version) then try to avoid turning the guess into an assumption without any evidence, and try to eliminate the hunch quickly (it will usually be wrong) by doing experiments.
A good experiment to start with is to plot how the performance varies with source document size.
- Status changed from New to Closed
- Assignee set to Michael Kay
I'm going to close this now as the original question is resolved.
If you need further help to resolve the performance issue, please open a new ticket with the evidence that we will need to reproduce the problem.
Please register to edit this issue
Also available in: Atom
PDF