Comments (5)
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:
- Probably best: Using a custom serializer on the container parse the xml manually and then use serialization for the values.
- You could do do some rewriting as in https://github.com/pdvrieze/xmlutil/blob/master/examples/DYNAMIC_TAG_NAMES.md
- You could also use the fact that if you have a list of
Node
instances it will work (note that text element serialization is broken - also marking it as XmlValue breaks). - Your handling of the content would work (have a look at the depth property to "deal" with nesting)
from xmlutil.
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 MapEntrySerializer
and DynamicTagReader
.
But, I'm coming to the realization that this approach is probably more work that it is worth, being that it is a minor part of the overall data model (the XML is the metadata of one object type in a vast sea of JSON). Being that our structure is not quite valid XML, I'm thinking maybe I should just revert back to doing dumb string building and parsing and use expect/actuals for the parts that don't have pure kotlin solutions (StringEscapeUtils.escapeXml11 in Apache Commons Text, for example).
from xmlutil.
@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 Node
s "should" work (but it doesn't due to a bug).
from xmlutil.
Related Issues (20)
- How to work with elements that have the same name and different attributes
- Is it possible to completely ignore namespaces during deserialization? HOT 2
- Default namespace on root element and unqualified child elements HOT 5
- IndexOutOfBoundsException: There are no children HOT 3
- Support for multiple alternative names during parsing? HOT 2
- Enums as XML attributes HOT 3
- Error when integrated into android (java) application HOT 2
- Add Multiple NameSpaces for a XML Element HOT 4
- XML NameSpace Prefix is incorrect for Non-Null Attribute HOT 2
- XmlUtil.xmlCollapseWhitespace() throws StringIndexOutOfBoundsException on empty attribute HOT 2
- @XmlClassDiscriminator HOT 1
- Boolean decoding should be strict by default, or at least optionally HOT 4
- DefaultXmlSerializationPolicy deprecated constructor HOT 10
- Partial regression on checking root tag name checking HOT 4
- Wrong order of contents and string parsing HOT 5
- Comments in XML will cause native DOM parser to fail HOT 2
- XmlOtherAttributes: deserialization replaces keys by its value HOT 4
- Add version supporting serialization 1.5.1 but keeping kotlin as 1.8.10 HOT 1
- Using namespace HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xmlutil.