-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generalize xml helper code #839
Conversation
This allows parsing of alternate file formats, and returning of alternate parsed data structures.
It seems old versions of Clang are not able to match the auto return type parameter in this context. The stock install of Clang on Ubuntu 18.04 is one of those old versions of Clang.
What are your thoughts about using element values instead of attributes to store data in dictionary format? More like what I did with PlanetAttributes.xml instead of the current save format? I am generally happy with the concept of storing data in dictionary form and planned to move more towards parsing in this fashion as discussed in the issues. I would just prefer it be in elements. Maybe best for me to switch to attributes though to be more consistent though... |
Curious question, under what conditions would you consider using attributes? I would certainly use element values for recursive structures. Outside of that, I find the choice is a little more arbitrary. |
Found some interesting discussion points here: |
Sorry for the long time between replies. I read the stack overflow you pointed to, and that article is striking the heart of what I'm talking about, in addition to the post it refers to at (https://stackoverflow.com/questions/33746/xml-attribute-vs-xml-element). It seems like there are 2 camps, OPHD sort of falls in the first camp that extensively uses attributes and I am used to the other camp. When writing XML, I avoid attributes almost exclusively unless it is metadata that does not belong in the actual structure of the parsed data. Current OPHD Serialization:
How I would have written the snippet:
How I would have written it is certainly more verbose. Probably a individual preference on which is easier to read. I would just accept the OPHD style here of using attributes, but I think it breaks down for large text fields. For example:
Versus how I think OPHD currently would format it using attributes:
(These fields probably should use the CDATA escapes. You may want to copy into notepadd++ or something similar to view. GitHub doesn't wrap the text in 'code' mode, and if I don't put it in code mode, it doesn't want to display it for probably good security reasons.) In the PlanetAttributes case the significant amount of text involved in the attributes reduces readability whereas the attributes looked cleaner with more numerical fields in the mine representation in the saved game. I would have probably just stuck with using attributes, but it seems incorrect in my mind to put large text blocks into attributes such as the PlanetDescription. In the past, I have hand written my XML field parsing, which means that a solution could be tailored either direction as needed. One of the downsides of hand writing the parsing is it tends to couple tightly with the implementation (XML in this case). I understand you are advocating for a universal dictionary approach in the project which would remove the tight coupling. Unfortunately, the universal approach becomes more complex if you create edge conditions such as if the text being serialized is a paragraph, use a child element, else always use attributes. Based on what I've read so far, I'm leaning towards rewriting the PlanetAttributes to use attributes for all stored data and more align with the current code base. Admittedly, I have read through some of the source code, played with some examples, and made a cursory read of most the associated issues, and have not really 'deep dived' the issue. Anyways, if this all sounds good, I would recommend merging this PR and I'll rewrite the PlanetAttributes to match this style. Then I can split PlanetAttributes to just parse a dictionary and push the parsing into NAS2D to remove all xml calls from PlanetAttributes. Thanks for reading. -Brett |
I would agree that attributes are not ideal for large blocks of text, and the In terms of using a consistent approach, that might only be relevant for the writing code. It would be possible to adapt the reading code so it could ingest data from either an attribute or a child element. In the case of planet data, it's static data packaged with the game, which will only ever be read. Previously there was some dual format read code to handle a custom "options" section, which was formatted a little differently. When loading the config file, it would parse either format, but then only save in the one consistent format. It was eventually removed though, after a transition period. I would be open to more dual format reading code. That would allow the planet data to be read as is, or perhaps with a mixed form where only the longer description field is an element. |
Ok, I've had a chance to re-read the code. I remember a couple of things I still wanted to work on:
As mildly frustrating as those flaws are, they're probably not worth holding back the code updates. Maybe they can be fixed in a future branch. I'm going to go with Brett's recommendation to merge. Particularly since other fresh items have been brought up that may depends on these or similar changes. |
Related to Issue #797, and PR #838.
It's been quite a little while since I worked on this (about 6 months). At this point I don't quite remember why I stopped and left it. I think there was something I was still working on, though maybe I just got busy with other stuff. It's a conflicting approach to PR #838. At any rate, I thought I'd push what I had as a point of comparison:
https://github.com/lairworks/nas2d-core/compare/generalizeXmlHelperCode?expand=1
Maybe some ideas will be worth taking from there.