Find optimum nested level in XML generation
This should cover W3C XML Schema, Relax NG and DTD related problems.
-
- Posts: 2
- Joined: Tue Aug 19, 2025 7:30 am
Find optimum nested level in XML generation
Hello All,
I have a set of complex xsd files where there are imports/includes across all the files. I am trying to generate a sample xml file using these xsd files from "Generate Sample XML Files" option. The aim is to generate the sample xml file, paste the xml in Visual Studio 2022 as class, generate a dll (class library) and to deserialize another xml (with actual data) which was generated using same xsds. The generated .cs file also is used in other classes in the project.
I am at wits end as I am not able to get the right configuration for "Generate Sample XML Files" as for every combination I get different issues. Sometimes instead of collections I get objects (setting "preferred number of options to 2 generated List in .cs file but the classes repeat), sometimes elements go missing, file size too big etc.
The user manual says discardOptionalElementsAfterNestedLevel can generate large files which is correct. How do I check the optimum setting for this variable?
Image shows file sizes generated for different discardOptionalElementsAfterNestedLevel settings
Niranjan
I have a set of complex xsd files where there are imports/includes across all the files. I am trying to generate a sample xml file using these xsd files from "Generate Sample XML Files" option. The aim is to generate the sample xml file, paste the xml in Visual Studio 2022 as class, generate a dll (class library) and to deserialize another xml (with actual data) which was generated using same xsds. The generated .cs file also is used in other classes in the project.
I am at wits end as I am not able to get the right configuration for "Generate Sample XML Files" as for every combination I get different issues. Sometimes instead of collections I get objects (setting "preferred number of options to 2 generated List in .cs file but the classes repeat), sometimes elements go missing, file size too big etc.
The user manual says discardOptionalElementsAfterNestedLevel can generate large files which is correct. How do I check the optimum setting for this variable?
Image shows file sizes generated for different discardOptionalElementsAfterNestedLevel settings
Capture.JPG
Thanks in advance.Niranjan
You do not have the required permissions to view the files attached to this post.
-
- Posts: 90
- Joined: Wed Aug 30, 2017 3:56 pm
Re: Find optimum nested level in XML generation
Hello Niranjan,
The behavior you are seeing is expected, since the "Generate Sample XML Files" action is meant primarily for creating an example instance for testing/documentation, not for producing a canonical instance that can be used directly for code generation.
The setting in question - "Discard optional elements after nested level" - controls how many levels of nested optional elements are generated before they are discarded.
If you set a low value, optional elements deeper than that level are skipped, meaning the file gets smaller, but content may appear incomplete.
If you set a high value, more optional elements are generated, and file size grows exponentially.
There isn’t a universal "optimum" value – it depends on the complexity of your schemas and how much of the optional structure you actually need in the sample. Often values between 2–4 are enough to demonstrate structure without exploding file size.
Best regards,
Teo
The behavior you are seeing is expected, since the "Generate Sample XML Files" action is meant primarily for creating an example instance for testing/documentation, not for producing a canonical instance that can be used directly for code generation.
The setting in question - "Discard optional elements after nested level" - controls how many levels of nested optional elements are generated before they are discarded.
If you set a low value, optional elements deeper than that level are skipped, meaning the file gets smaller, but content may appear incomplete.
If you set a high value, more optional elements are generated, and file size grows exponentially.
There isn’t a universal "optimum" value – it depends on the complexity of your schemas and how much of the optional structure you actually need in the sample. Often values between 2–4 are enough to demonstrate structure without exploding file size.
Best regards,
Teo
Teodor Timplaru
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ Artificial Intelligence (AI Positron Assistant add-on)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service