-
Notifications
You must be signed in to change notification settings - Fork 113
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
XmlEncoder: ordering of elements #17
Comments
Hi @Ma-He, thank you reporting this issue. There's a We plan to publish auto-generated docs for Also, if you're using this option, you might need to switch to |
Sorting is not was OP is looking for. Ordering is. That is This is not supported currently as XMLCoder uses unordered |
Thanks @regexident, I understand now. Still, my understanding was that the main concern is about determinism. I hope that |
I'm fairly certain as writing a GPX (like many other XML schemas) expects certain keys to have a specific order: Search for This requirement of specific order also applies to elements, not just attributes. |
Hey guys, thanks for your quick responses. As @regexident said, ordering it is what I`m looking for :-) |
) This PR removes any remaining use of `NS…Array`/`NS…Dictionary`/`NSNumber`/`NSDecimalNumber`/`NSNull`/… (as storage) from the code-base. It introduces an internal type … ```swift internal enum Box { case null(NullBox) case bool(BoolBox) case decimal(DecimalBox) case signedInteger(SignedIntegerBox) case unsignedInteger(UnsignedIntegerBox) case floatingPoint(FloatingPointBox) case string(StringBox) case array(ArrayBox) case dictionary(DictionaryBox) } ``` … as well as accompanying variant box types, replacing use of `Any`/`NS…`. 👷🏻♀️It improves type-safety by reducing use of `Any` (from 60 down to 19 occurrences) as well as `NSObject` (from 37 down to 1 occurrence). 🏗It further more levels the field for improvements/additions such as [support for order-preserving elements & attributes](#17). 💡Thanks to encapsulation we can now safely change the inner logic of `DictionaryBox` to retain insertion order. **Edit**: We ended up replacing aforementioned `enum Box` with a protocol: ```swift protocol Box { var isNull: Bool { get } var isFragment: Bool { get } func xmlString() -> String? } ``` * Added basic box types * Migrated decoding logic to proper boxes * Migrated encoding logic to proper boxes * Moved auxiliary types into their own dedicated files and group * Replaced use of `.description` with explicit dedicated `.xmlString` * Made box types conform to `Equatable` * Added basic unit tests for box types * Removed manual `Equatable` conformance, changed fragment boxes to structs * Removed redundant use of `internal` on internal types * Simplified logic of `func createElement` instances * Removed `enum Box` in favor of `protocol Box` * Fixed error description for `.typeMismatch` * Shortened type names of `FloatingPointBox`, `SignedIntegerBox` and `UnsignedIntegerBox` * Moved unboxing logic into dedicated Box initializers * Removed last remaining use of explicit `internal` related to this PR * Changed `Unboxed` types of `IntBox` & `UIntBox` to explicit 64bit types * Made `.xmlString` conform to W3.org’s XML-spec * Renamed `.init(string:…)` to `.init(xmlString:…)` * Implemented conformity to encoding strategies * Simplified box unit tests * Added minimalist decoding unit tests for individual box types * Fixed bug related to `Float` encoding and simplified internal encoding/decoding locig
Nitpick: It's not the order of attributes that's unsupported, it's the order of elements. The XML specification explicitly defines the order of attributes to be of no importance:
As such |
TLDR: We're slowly working towards ordered child elements, but not quite sure if ordering of attribues will be possible in the current implementation. @Ma-He could you please clarify if you're looking for ordering of XML attributes or child elements? |
If you're specifically interested in supporting GPX, looks like it only requires ordered elements, not attributes. |
@MaxDesiatov you`re right, just the elements |
Unifies the representation of `T` where `T: Box` and makes it explicit where shared reference semantics is expected. With this code performance is consistently 5-30% worse, could this be caused by copies of value types? Can this be improved when Swift 5.0 is released or whatever the version is that allows us to improve performance of value types? After reviewing related issues we'd prefer XMLCoder to be slightly slower, but with #12, #17 and #25 fixed than the opposite 😞 * Added `SharedBox` type for on-demand reference semantics * Remove `print` that kills performance tests * Handle all cases with SharedBox containers * Add RJITest back to the project file, fix the test * Remove unused internal initializer
I have to say you doing great job! |
Resolves #17 * First attempt at ordered encoding * Fix line length linter warning * Rename DynamicNodeEncoding function, fix order
Add benchmark baselines Pull in tests (CoreOffice#11) Add Decoding support for choice elements (CoreOffice#15) Fix indentation (CoreOffice#16) Replace usage of XCTUnrwap (CoreOffice#19) Add nested choice tests (CoreOffice#18) Add falsely passing double array roundtrip test (CoreOffice#17)
Add benchmark baselines Pull in tests (CoreOffice#11) Add Decoding support for choice elements (CoreOffice#15) Fix indentation (CoreOffice#16) Replace usage of XCTUnrwap (CoreOffice#19) Add nested choice tests (CoreOffice#18) Add falsely passing double array roundtrip test (CoreOffice#17)
Hi,
is there any possibility to set the order of attributes in an element while encoding a model-instance?
I'm trying to build a GPX reader/writer with this little awesome framework and have noticed that the order of my attributes in an element varies from encode to encode. Am I missing something?
Thanks in advance
The text was updated successfully, but these errors were encountered: