-
Notifications
You must be signed in to change notification settings - Fork 31
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
How to simply parse/serialize a Map to/from XML that has keys as tag names wrapping text values. #192
Comments
The challenge is that this is not quite valid Xml. Tag names are intended to be well-defined. I would consider custom parsing the best solution (if you do this in a custom serializer you can still parse the values using serialization). However, there are other options:
|
Thank you! I've actually already started implementing the dynamic tag names approach serializing a Map instead of a List. Serializing the Map without nesting worked straightaway, but I have not successfully parsed out values with |
@gladapps You don't need to go to raw parsing with regexes or something. You can use the (separate) xml parsing support from the core library. You just create your parser, then read events, if it is a tag handle it (read the value (perhaps recursively), then add it to your list). It is serialization that doesn't like it (it makes too many assumptions), not the xml parser. However, parsing a list of |
@pdvrieze Is there an example of creating own parser with read events and tag handles? Would love to have a look at it. |
@susrisha The way to go is to use the object Note that you don't need the serialization part of the library for this, only core. |
I'm trying to simply parse a format like this:
into a Map<String, String> with the entry keys being the tag names:
I've made my own policy that overrides
handleUnknownContentRecovering
and just puts the keys and values into a single Map like this:dataMap[input.name.toCName()] = input.elementContentToFragment().contentString
and returns the Map for
elementIndex = 0
. But I'm not sure what to do about the nested tags.I also need to serialize such a Map.
I've tried using the existing
MapEncoder
, but I don't need keys and values to have their own tags. Maybe it can work if the entry name could use the key name and omit the key element, with the value collapsed. But I couldn't figure out how to get it to do that.Any help would be greatly appreicated.
The text was updated successfully, but these errors were encountered: