I am creating an XSD/CAM prototype to model a disk filesystem. I am using the free CAMed software along with Windows Notepad (for when I run into bugs in the CAMed software.) In my prototype I have an element called “Hold.” A Hold tells the filesystem to hold on to (not delete) a directory, file, etc. because it is needed by an application. (Think of a Hold as somewhat like a hard link.) In the prototype, the Hold element can be a child of several elements, not just one, but is identical in all cases. Ordinarily, I would simply copy and paste the Hold element inside each parent it belongs under (e.g. directory, file, etc.,) however, the CAMed software doesn’t have that capability and I don’t feel like manually copying and pasting the XML in notepad (I would then have many copies to update and manage.)
Is it possible to specify that an element can belong to more than one parent, without duplicating the original element definition? Thanks!
Sure. Define a top-level element named Hold. (By ‘top-level’ is meant that the declaration appears as a child of xs:schema and is not local to a particular complex type.) Then refer to that element declaration from the complex types in which Hold should appear.
So your declaration of Hold will look like this:
And your declarations of the types for directory, file, etc. will refer to Hold, using the ref attribute on the xs:element element, rather than declaring a local Hold element using the name attribute:
Here, the elements ‘blort’ and ‘farble’ are local declarations, while ‘Hold’ and ‘cadwallader’ are references to top-level declarations supplied elsewhere.