Creating Full Test XML Data Possibilities with Deeply Nested 'Choice' from XSD

This should cover W3C XML Schema, Relax NG and DTD related problems.
oxygenuser1
Posts: 2
Joined: Fri May 03, 2019 5:18 pm

Creating Full Test XML Data Possibilities with Deeply Nested 'Choice' from XSD

Post by oxygenuser1 »

Hello! I am trying to generate an all-encompassing test XML that has every possible field from the XSD. There are many instances where I have 'Choice' elements that have grandchildren/great-grandchildren that contain additional 'Choice' elements. XSD file size is roughly 15,000 lines, and when we run through the "Generate Sample XML" function from the XML Editor, it will comment out 'Choice' Elements, but won't build out the commented branch. Any advice would be greatly appreciated!

Jeff
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

Re: Creating Full Test XML Data Possibilities with Deeply Nested 'Choice' from XSD

Post by adrian »

Hello,

Unfortunately when there are grandchildren/great-grandchildren choices only one is selected to be generated and the others aren't generated at all.
We have an improvement request for this on our issue tracking tool. I've added another vote and mentioned your comment.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
oxygenuser1
Posts: 2
Joined: Fri May 03, 2019 5:18 pm

Re: Creating Full Test XML Data Possibilities with Deeply Nested 'Choice' from XSD

Post by oxygenuser1 »

Thanks so much! I was actually able to circumvent the issue by adjusting the XSD slightly from 'choice' to 'sequence' and updating some of the formatting accordingly! Was wondering if there was functionality to get a list of all possible XPaths from an XSD/XML. Any insight into that would be greatly appreciated!

Thanks,
Jeff
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

Re: Creating Full Test XML Data Possibilities with Deeply Nested 'Choice' from XSD

Post by adrian »

Hi,

Here's a quick XQuery that does what you want on an XML instance. Can be run in the XPath/XQuery Builder with Saxon-PE XQuery:

Code: Select all

distinct-values(
for $path in //(*|@*)
return replace(replace(path($path), "Q\{.*?\}",""), "\[\d+\]", "")
)
This also covers XPaths to attributes. If you want only element XPaths, replace "//(*|@*)" with "//*"
Note that this strips down namespaces.
If you want absolutely every XPath of all XML nodes including comments, PIs and text, use "//node()".

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Post Reply