Software Development

Xerces C++: Validate Slow XML Validation Against XSD With Unique And Key Elements

We have encountered a performance issue with Java validating an XML with 300,00 elements against an XSD with <xs:unique> and <xs:key>.  This post uses Xerces C++ to parse and validate a huge XML against an XSD with those elements. Also, it attempts to validate the performance issue outside the Java ecosystem.

Requirements

We use the following items for this post. Note that we will not create any C/C++ codes.

  • Xerces C++ binaries
  • An XSD file that uses the unique and key constraints
  • A huge XML file to parse and validate
  • Windows 10
    • C/C++ IDE, .e.g, CLion 2021.3.4
  • PilotEdit Lite
    • To edit a huge XML file, we need to reference a local XSD file.

Download Xerces C++ Source Codes And Compile Them

First, we need to download Xerces C++ binaries for Windows.

Test Faulty XSD File With Xerces C++ PParse.exe

Then, we test our XML file with a faulty XSD using Xerces C++ Parse.exe executable. For example, consider the following faulty XSD that will cause the performance issue.

Note that this XSD uses a unique constraint element. Similarly, the key constraint element will cause the same problem. Next, place the XML and XSD files in the Xerces C++ bin directory below.

Xerces C++: Validate Slow XML Validation Against XSD With Unique And Key Elements

Then, we modify the XML to refer to the XSD file in the same directory explicitly.

Next, we use the PParse.exe file to parse and validate our XML file.

Testing  Xerces C++ With The Unique Constraint

We can see that the application has not yet completed the validation after ~5 to 6 minutes. The operation has taken too much time to complete already.

Xerces C++: Validate Slow XML Validation Against XSD With Unique And Key Elements

Testing Xerces C++ Without The Unique Constraint

This time it took only 323 ms. Great!

Xerces C++: Validate Slow XML Validation Against XSD With Unique And Key Elements

Did We Validate The XML Against the XSD?

Yes! We used an invalid element, “nameXX,” and the XML validation failed.

Using <xs:unique> or <xs:key> elements for validation is fine. However, if we process many elements, using these constraints hurts an application’s performance.

Loading

Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.


You Might Also Like