File format specification #1011
-
Is there a specification for the .nwx project file format that says something about the order of content item entries? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 15 replies
-
The order of the content in the XML is the linear order of items in the project tree from top to bottom. Linear meaning it ignores the parent/child hierarchy (column number) and follows the row number. You can rely on this being the case when novelWriter writes the XML. However, the parent reference is needed in order to re-create the tree structure when the project is loaded, otherwise it would end up as a flat list. The order attribute is presently redundant though. It is mostly written to the XML for debug purposes. The algorithm that loads the project tree is able to handle cases where the content entries in the file have been re-ordered or appear in the wrong order from a hierarchical point of view. It will detect, for instance, if a child item is loaded before its parent item, in which case it will postpone the loading of that item and try again later. So the loading is robust in terms of parent/child relationship, but a re-ordered XML will still mess up the order of sibling items at any given level. Postponing the loading of an item will also put it in the wrong location after the tree is built. Since the intended order is saved to the XML, I could write code that reorders the final tree based on the order attribute in the XML, but since there is no scenario internally in the XML handling that could produce such an outcome as it stands. Therefore I never prioritised this. Of course, when the file is generated externally such a scenario is possible, so if needed I can look into this. In that case, the order of entries in the XML would in principle no longer matter at all. The early versions of novelWriter ran on Python 3.4 and up, and prior to 3.6 the entries of a dictionary were ordered by their hash key. Since Python 3.6 the order is effectively the same as they were added, although this isn't guaranteed until Python 3.7. Due to the history of Python version support, the project content is stored separately (in a dict) from the project order (in a list) and there are the mentioned checks on loading that makes sure everything is ok before it is loaded into the project tree widget. From next release I'm dropping Python 3.6, so now it's actually possible to redesign this process, but I will not change the XML format in any case. For reference, the function that serves the entries to the tree widget during load time can be found here: novelWriter/novelwriter/core/project.py Lines 1143 to 1183 in 7f43584 |
Beta Was this translation helpful? Give feedback.
-
I'm looking at the new file format and am considering updating my yWriter file converter. |
Beta Was this translation helpful? Give feedback.
The order of the content in the XML is the linear order of items in the project tree from top to bottom. Linear meaning it ignores the parent/child hierarchy (column number) and follows the row number. You can rely on this being the case when novelWriter writes the XML. However, the parent reference is needed in order to re-create the tree structure when the project is loaded, otherwise it would end up as a flat list. The order attribute is presently redundant though. It is mostly written to the XML for debug purposes.
The algorithm that loads the project tree is able to handle cases where the content entries in the file have been re-ordered or appear in the wrong order from a hierarchica…