Choosing XML element vs attribute
-
Hi All,
I'm hoping to get feedback from Qt Xml experts.
I am aiming to reconstruct a .txt file of the following format from XML file.
P P0 "Phase zero" 0ms NONE 2000ms STOP STOP STOP O CH1 0mA 0ms 0ms 600000ns 180us RATE O CH2 0mA 0ms 0ms 600000ns 180us RATE O CH3 0mA 0ms 0ms 600000ns 180us RATE P P1 "Phase one" 0ms NONE 2000ms STOP STOP STOP O CH1 0mA 0ms 0ms 600000ns 180us RATE O CH2 0mA 0ms 0ms 600000ns 180us RATE O CH3 0mA 0ms 0ms 600000ns 180us RATE
Each node has a
reference
(P
orO
). The nodeparameters
are presented as a list of space separated variables. The parameter values are collected using widgets likespin box
,vertical sliders
etc.I'm a bit confused to determine the structure of the XML file recreates the above mentioned txt file. Should I use XML
elements
or XMLattribute
or combination of both to easily reconstruct?I really appreciate if someone can show me an example.
Thanks in advance
-
Hi,
Your description is a bit unclear. Do you have XML data that you want to convert ? Or are you reading that txt file and want to translate it to XML ?
-
@viniltc
For an XML representation like this (where the elements do not break down into sub-elements themselves), it truly does not matter whether you choose an element, attribute or mixture schema, it's up to you, both are valid and will be seen in various implementations.If I have a lot of elements I tend to prefer XML elements over attributes for sure, because they are easier to see/manage. If I regard something as a "property" I might go attribute.
Here you seem to have 7 elements to associate with each
P
orO
. My inclination would be to go sub-elements rather than attributes just because of the number, but both are valid.The fact of Qt Xml is neither here nor there for the decision, it will handle either as it should.