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

v1.0 #61

Merged
merged 4 commits into from
Nov 22, 2024
Merged

v1.0 #61

Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 45 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,56 @@

## What is it?

`MetronInfo.xml` is an attempt to create a new schema for digital comic books that fixes some of the deficiencies that exist with the `ComicInfo.xml` schema.
`MetronInfo.xml` is an attempt to create a new schema for digital comic books that fixes some of the deficiencies that
exist with the `ComicInfo.xml` schema.

## Rationale

The `ComicInfo.xml` schema was designed for the needs of ComicRack Application (which for all intents is a dead project), and supports a fairly limited amount of data. Some benefits of a new schema would include:
The `ComicInfo.xml` schema was designed for the needs of ComicRack Application (which for all intents is a dead
project), and supports a fairly limited amount of data. Some benefits of a new schema would include:

- Additional `Elements` for information. (eg. Price, Global Trade Item Numbers, Series Type, etc.)
- Better handling of data types. Instead of using delimited strings for list items, we can use Arrays of `Elements`.
- Ability to identify where the data was obtained from. (eg. Comic Vine, Metron, Grand Comics Database, etc.)
- Add `ID` elements from the Information Source to resources (Characters, Creators, etc), so items with the same name are associated correctly if used in a Plex-like Comic Server.
- Additional `Elements` for information. (e.g. Price, Global Trade Item Numbers, Series Type, etc.)
- Better handling of data types. Instead of using delimited strings for list items, we can use Arrays of `Elements`.
- Ability to identify where the data was obtained from. (e.g. Comic Vine, Metron, Grand Comics Database, etc.)
- Add `ID` elements from the Information Source to resources (Characters, Creators, etc.), so items with the same name
are associated correctly if used in a Plex-like Comic Server.

Since Digital Comics are just are archive files (like .zip) this new XML schema can co-exist with any existing `ComicInfo.xml` if needed for backward compatibility.
Since Digital Comics are just are archive files (like .zip) this new XML schema can co-exist with any existing
`ComicInfo.xml` if needed for backward compatibility.

## Is the schema only for the Metron Database?

No, the schema only has *Metron* in the name since almost every other format has *Comic* in the name, and the
originating author hates naming projects, so he went with the simplest choice. 😄 It was designed to be used for any of
the
comic resources (Comic Vine, AniList, etc.)
bpepple marked this conversation as resolved.
Show resolved Hide resolved

## Where can I find the schemas?

Currently only a draft is available located in [drafts](./drafts)
Version 1.0 of the schema is located in [schema](./schema) directory

## How can I validate my XML?

It's recommended that any software that writes the XML make use of the schema to validate, so consumers of the XML
document can be sure of its data. The schema use XSD 1.1, so you need to make sure your validation code uses that
instead of XSD 1.0.

For example to validate the XML in python:
```python
from pathlib import Path
from xmlschema import XMLSchema11, XMLSchemaValidationError

xsd = Path("/home/user/MetronInfo.xsd")
xml = Path("/home/user/MetronInfo.xml")

schema = XMLSchema11(xsd)
try:
schema.validate(xml)
except XMLSchemaValidationError as e:
print(f"Failed to validate XML: {e!r}")
exit(1)

# Code to write / read the xml file
```


File renamed without changes.
File renamed without changes.
10 changes: 5 additions & 5 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
from xmlschema import XMLSchema11, XMLSchemaValidationError

TEST_XSD = Path(__file__).parent.parent / "drafts" / "v1.0" / "MetronInfo.xsd"
TEST_XSD = Path(__file__).parent.parent / "schema" / "v1.0" / "MetronInfo.xsd"
TEST_FILES_PATH = Path(__file__).parent / "test_files" / "v1.0"


Expand All @@ -13,12 +13,12 @@
(TEST_XSD, TEST_FILES_PATH / "valid.xml"),
(
TEST_XSD,
'<?xml version="1.0" encoding="UTF-8"?><MetronInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
'<?xml version="1.0" encoding="UTF-8"?><MetronInfo>'
"<Series><Name>Foo</Name></Series><Number /><PageCount>0</PageCount></MetronInfo>",
),
(
TEST_XSD,
'<?xml version="1.0" encoding="UTF-8"?><MetronInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
'<?xml version="1.0" encoding="UTF-8"?><MetronInfo>'
"<Series><Name>Foo</Name><Volume>0</Volume></Series><Number /></MetronInfo>",
),
],
Expand All @@ -35,12 +35,12 @@ def test_valid(xsd: Path, xml: Path | str) -> None:
(TEST_XSD, TEST_FILES_PATH / "dup_primary_attr.xml"),
(
TEST_XSD,
'<?xml version="1.0" encoding="UTF-8"?><MetronInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
'<?xml version="1.0" encoding="UTF-8"?><MetronInfo>'
"<Series><Name>Foo</Name></Series><Number /><PageCount>-1</PageCount></MetronInfo>",
),
(
TEST_XSD,
'<?xml version="1.0" encoding="UTF-8"?><MetronInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
'<?xml version="1.0" encoding="UTF-8"?><MetronInfo>'
"<Series><Name>Foo</Name><Volume>-1</Volume></Series><Number /></MetronInfo>",
),
],
Expand Down
2 changes: 1 addition & 1 deletion tests/test_files/v1.0/dup_primary_attr.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<MetronInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<MetronInfo>
<IDS>
<ID source="Metron" primary="true">290431</ID>
<ID source="Comic Vine" primary="true">12345</ID>
Expand Down
2 changes: 1 addition & 1 deletion tests/test_files/v1.0/valid.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<MetronInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<MetronInfo>
<IDS>
<ID source="Metron" primary="true">290431</ID>
<ID source="Comic Vine">12345</ID>
Expand Down