GithubHelp home page GithubHelp logo

"Token StartElement in state Epilog would result in an invalid XML document" on InvoiceDescriptor.Save(stream, v21, Basic) about zugferd-csharp HOT 6 CLOSED

springy76 avatar springy76 commented on June 12, 2024 1
"Token StartElement in state Epilog would result in an invalid XML document" on InvoiceDescriptor.Save(stream, v21, Basic)

from zugferd-csharp.

Comments (6)

stephanstapel avatar stephanstapel commented on June 12, 2024 1

The answer seems to be quite simple:

The internal setter of trade line items prohibts creating them by the deserializer:

public List<TradeLineItem> TradeLineItems { get; internal set; } = new List<TradeLineItem>();

Working alone in my spare time on the project, I am happy to accept your sponsoring:
https://github.com/sponsors/stephanstapel

from zugferd-csharp.

stephanstapel avatar stephanstapel commented on June 12, 2024

Hi @springy76,
it is really hard to guess what might have gone wrong based on the exception. Can you please provide your unit test (working without any dependencies) and the file that is generated?

from zugferd-csharp.

springy76 avatar springy76 commented on June 12, 2024

Since the surrounding code goes through several layers of abstraction and transformation code I can't provide a simple sample, but I serialized the final InvoiceDescriptor to json. Note that TradeLineItems does not get deserialized, but I guess this is something you can fix easily since everything else looks good so far.

var jsonSerializerOptions = new JsonSerializerOptions { WriteIndented = true, Converters = { new JsonStringEnumConverter() { } } };
var json = JsonSerializer.Serialize(invoiceDescriptor, jsonSerializerOptions);
var rebuilt = JsonSerializer.Deserialize<InvoiceDescriptor>(json, jsonSerializerOptions);
var json2 = JsonSerializer.Serialize(rebuilt, jsonSerializerOptions);
Debug.Assert(json2 == json);

InvoiceDescriptor.zip

from zugferd-csharp.

stephanstapel avatar stephanstapel commented on June 12, 2024

I'm sorry, but generating the file from the data you provided works without any problem. Please try:

var jsonSerializerOptions = new JsonSerializerOptions { WriteIndented = true, Converters = { new JsonStringEnumConverter() { } } };
var json = File.ReadAllText("InvoiceDescriptorSerialized.json");
InvoiceDescriptor rebuilt = JsonSerializer.Deserialize<InvoiceDescriptor>(json, jsonSerializerOptions);
rebuilt.Save("output.xml", ZUGFeRDVersion.Version21, Profile.Basic);

from zugferd-csharp.

springy76 avatar springy76 commented on June 12, 2024

As said, currently all TradeLineItems get stripped/ignored during Deserialize - and they seem to be the error source when they exist. If you add those 2 lines to your code you'll see:

var json2 = JsonSerializer.Serialize(rebuilt, jsonSerializerOptions);
Debug.Assert(json2 == json); // not equal, entire TradLineItems-Subtree/-Array is empty

from zugferd-csharp.

springy76 avatar springy76 commented on June 12, 2024

The internal setter of trade line items prohibts creating them by the deserializer:

Klarer Fall von "Softwareproblem, kann man nichts machen" .

Irgendwie hatte ich die völlig irre Annahme, dass das auch in Bezug auf andere Bugreports - völlig losgelöst von diesem Issue - von Hilfe wäre, wenn man einen InvoiceDescriptor nicht nur serialisieren, sondern auch verlustfrei deserialisieren kann.

from zugferd-csharp.

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.