Skip to content
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

Create Onix file #3

Closed
DGPRodrigues opened this issue Sep 17, 2020 · 4 comments
Closed

Create Onix file #3

DGPRodrigues opened this issue Sep 17, 2020 · 4 comments
Labels

Comments

@DGPRodrigues
Copy link

Hello jearith, first I want to congratulate you for this excellent project.

I work at a publisher in Brazil, and starting next month, our system should generate Onix files to insert in the portals of Google, Amazon, Kobo and Apple.

I loved your project and would like to know if I can generate ONIX files with it.
I made an example and it generates the file with duplicate Tags.

I also don't know if it is possible to insert "refname" in short tags, insert version and xmlns in ONIXmessage

Can you help me?

@DGPRodrigues
Copy link
Author

image
My Onix File

image
My Code

@jaerith
Copy link
Owner

jaerith commented Sep 17, 2020

First, thanks for the compliment. When people give the project a star, I'm glad to know that somebody else has found a use for it.

Now, as to the issue at hand, I'm a bit surprised, since I never thought of this use case. Honestly, I never thought about people using this project to write ONIX files. Likely, I didn't think of it since many publishers use services/software to generate their ONIX files. Of the publishers that I deal with, a popular choice is Firebrand Technologies, but I'll admit that I don't know the costs involved. But, yes, you are right - it would make sense to have an open source alternative.

Unfortunately, this project at the moment won't really be an ideal choice for writing out ONIX files, since it was just meant to ingest ONIX data. Since the ONIX standard is complicated and since there are many possible tags to use for the same data (reference tags vs. short tags), the created classes were supposed to anticipate these different scenarios for parsing, with the resulting classes having many properties. (This is the reason why you're observing so many tags in your output.) In C#, it's not exactly easy to use code for ignoring these properties upon serialization, but supposedly, something like the following could help you (though I've never actually used it):

var attributes = new System.Xml.Serialization.XmlAttributes { XmlIgnore = true };

var overrides = new System.Xml.Serialization.XmlAttributeOverrides();
overrides.Add(typeof(OnixHeader), "header", attributes);

var serializer = new System.Xml.Serialization.XmlSerializer(typeof(OnixMessage), overrides);

Perhaps one day I'll get around to working on a feature that successfully serializes these classes. It's definitely a good idea!

@DGPRodrigues
Copy link
Author

Hi jaerith, thanks for the reply.

In Brazil there is a company that generates these Onix files, but with high production costs and the low quantity sold (e-book in Brazil is becoming popular now), the publisher decided to invest in its own system to generate these files.

I will check this tip you gave.

Its framework generating and consulting the Onix file, would be a perfect solution.

I will try to do something simple in your solution.

I will send news in the future.

Thank you,
Daniel

@jaerith
Copy link
Owner

jaerith commented Sep 18, 2020

There is of course another way, a horrible, terrible hack: you could serialize the OnixMessage class, and with regular expressions or some code, then:

1.) if you want Reference tags, remove any composite sections (like "<header>") or single lines where the tag name starts with a lowercase letter
2.) if you want Short tags, remove any composite sections (like "<Header>") or single lines where the tag name starts with a capital letter

You'll have to plan accordingly for tag values with embedded newlines. It's a horrible hack, but it might be a fast and dirty solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants