[xsd-users] Lazy loading

Boris Kolpackov boris at codesynthesis.com
Mon Jan 24 08:31:52 EST 2022


Lars Sunde <laasunde at hotmail.com> writes:

> Does XSD 4.0 support any form of lazy loading of nodes in an XML file?
> Xerces uses the term "defer-node-expansion".

Hm, never heard of this feature. A bit of web and source code searching
suggest it's a Xerces-J only feature and not supported by Xerces-C++.


> We are currently parsing an XML file that contain elements with
> String or integer or base64Binary data types. It is a runtime
> decision whether the application needs to parse the base64 data.
> It would improve performance if the base64 elements were loaded
> only when actually needed. Does XSD support such a solution?

Not directly but you can probably arrange for something like this using
the streaming parsing model. There is the `streaming` example that shows
the approach. Quoting from its README:

> This example shows how to perform stream-oriented, partially in-memory XML
> processing using the C++/Tree mapping. With the partially in-memory parsing
> and serialization only a part of the object model is in memory at any given
> time. With this approach we can process parts of the document as they become
> available as well as handle documents that are too large to fit into memory.

So what your could do is parse each chunk of XML into DOM, if the base64
elements are not needed, reset them to empty values (or remove them if
the schema allows them to be absent), and then parse the DOM fragment to
C++ object.



More information about the xsd-users mailing list