Though I know a little about XML and XML Schema I haven’t used it in ages and have never been particularly competent in its use.
Therefore a little help with the following would be really appreciated.
We currently receive delimited data files and would like to switch to XML files validated by an XML Schema.
The current delimited file contains a trailer record that includes a record count.
e.g.: TRL0000155
In the XML version, should this record count be included as an attribute of the main <data_file> element
<data_file record_count="155">
<record>
record XML...
</record>
<record>
record XML...
</record>
...
</data_file>
or as a child element of <data_file>
<data_file>
<record_count>155</record_count>
<record>
record XML...
</record>
<record>
record XML...
</record>
...
<data_file>
or perhaps I am going about it all wrong and you could give me a tip on the correct method for replacing the record count entirely.
I do recognise the difference between elements and attributes but in this case I am hoping it’s an issue that many have come across before and can offer a good explaination of why one is the preferred solution.
FWIW I am leaning more towards the attribute solution as the count is metadata about the <data_file> element but am happy to follow more expert instruction.
Thanks in advance…
Since you have a
<record>element for each record, there’s technically no need for the record count to be explicit. You can still have it, of course, for example if it helps performance. But on the other hand, it introduces the issue that it has to be kept consistent with the number of<record>elements.If you do decide to store the record count, both of your approaches (attribute and element) are ok. The main difference is that when you (if you) build the string content of the file, attributes are ignored, while the text nodes in the elements are not. So the count would show up in the second case but not in the first.
If you can apply XPath to the XML file, determining the record cound is easy; that would just be
count(/data_file/record). In that case there’s really no need to store the value explicitly.