Page 1 of 1
Creating Full Test XML Data Possibilities with Deeply Nested 'Choice' from XSD
Posted: Fri May 03, 2019 5:32 pm
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
Re: Creating Full Test XML Data Possibilities with Deeply Nested 'Choice' from XSD
Posted: Wed May 08, 2019 5:13 pm
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
Re: Creating Full Test XML Data Possibilities with Deeply Nested 'Choice' from XSD
Posted: Wed May 08, 2019 5:35 pm
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
Re: Creating Full Test XML Data Possibilities with Deeply Nested 'Choice' from XSD
Posted: Thu May 09, 2019 5:59 pm
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