Giter VIP home page Giter VIP logo

Comments (5)

pdvrieze avatar pdvrieze commented on May 25, 2024

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.

gladapps avatar gladapps commented on May 25, 2024

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.

pdvrieze avatar pdvrieze commented on May 25, 2024

@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 Nodes "should" work (but it doesn't due to a bug).

from xmlutil.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.