Open
Description
Have things attributes, instead of child elements,
if they are simple and describe the entity/element and don't need to be contained.
from things like this
<workflow>
<task>
<uid>fsdkfjklsdf<uid>
<name>my task<name>
<startDate>2020-07-10T15:00:00Z</startDate>
<endDate>2020-07-10T16:00:00Z</endDate>
<command>ls -lisah .</command>
<command>rm -rf foo</command>
<task>
<workflow>
to this like this
<workflow>
<task uid="fsdkfjklsdf"
name="my task"
startDate="2020-07-10T15:00:00Z"
startDate="2020-07-10T16:00:00Z"
>
<command>ls -lisah .</command>
<command>rm -rf foo</command>
<task>
<workflow>
benefits of attributes over elements:
- i could write XPATH queries easily for an element based on some attribute. selecting on a child-element with a certain content is hard
- said XPATH could be used in XSD's
key
andkeyref
andunique
constraints and rules. - said XPATH could be used by downstream consumers of a BOM xml, if they want to query the document.
examples:
- i could query one/all BOM documents ad find all tasks that have a dateDiff of started-to-done-interval of more than 10 minutes,
instead of jumping to:parent
here and there (if it was possible with nested-elements at all)
PS: you guys told me it was hard for you to get an idea what should be an attribute in XML and what a nested element, as you are more used to JSON and YAML.
maybe this helps to get the right idea:
- if you write a property in JSON schema, then it is an attribute in XML, not a nested element.
- If you write an array JSON schema, then the elements should be nested in XML, not attributes.