I’m creating an XML schema which keeps track of information regarding the source/origins of a file.
I would like to set up a child-parent structure like my below example so I don’t have to keep track of relationships on linear list of meta elements.
Is this okay? Is there any reason this would not be recommended?, If not, what’s the right way?
XML Structure
<meta> <!-- root -->
<info/>
<sources>
<source>
<meta> <!-- circular reference -->
<info/>
<sources>
<source>
<meta>...</meta> <!-- circular reference -->
</source>
</sources>
</meta>
</source>
<source>
<meta> <!-- circular reference -->
<info/>
<sources>
<source>
<meta>...</meta> <!-- circular reference -->
</source>
</sources>
</meta>
</source>
</sources>
</meta>
I think you mean, is it okay for an element to have a descendant with the same element-type name?
Sure; lots of XML vocabularies use recursive elements. The (X)HTML div element is an example you will probably be familiar with.
The advantage of recursion is typically that it simplifies the vocabulary; the main disadvantage is that it requires processors (and the people who write them) to keep track of the recursion. That’s very easy in many contexts, and can be awkward in others.
You do need to make sure that the recursive element is not required as a child or descendant of itself; otherwise it’s impossible to have any valid finite documents.