Skip to content

Commit

Permalink
Simplify IDS & URLS elements
Browse files Browse the repository at this point in the history
Use a solution that AJ suggested to simplify the ID and URL elements by using an assert to ensure only one `primary` attribute

This solution requires xsd-1.1

Refer to: https://github.com/ajslater/xsd_assert_example
  • Loading branch information
bpepple committed Oct 29, 2024
1 parent 9d23190 commit dd6941c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 34 deletions.
36 changes: 14 additions & 22 deletions drafts/v1.0/MetronInfo.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<!-- Complex Types -->
<xs:complexType name="metroninfoType">
<xs:all>
<xs:element name="ID" type="sourcesType" minOccurs="0" />
<xs:element name="IDS" type="idsType" minOccurs="0" />
<xs:element name="Publisher" type="publisherType" minOccurs="0" />
<xs:element name="Series" type="seriesType" />
<xs:element name="Volume" type="xs:string" minOccurs="0" /> <!-- This is used for Manga -->
Expand Down Expand Up @@ -36,39 +36,31 @@

<xs:complexType name="urlsType">
<xs:sequence>
<!-- The following element should be for the primary source url -->
<xs:element name="Primary" type="xs:string" />
<!-- The following should be used for any additional urls -->
<xs:element name="Alternatives" type="AltUrl" minOccurs="0" />
<xs:element name="URL" type="urlType" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
<xs:assert test="count(URL[@primary = true()]) &lt;= 1" />
</xs:complexType>

<xs:complexType name="AltUrl">
<xs:sequence>
<xs:element name="Alternative" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>


<xs:complexType name="sourcesType">
<xs:sequence>
<!-- The following element should be used for the primary source of metadata information. -->
<xs:element name="Primary" type="sourceType" />
<!-- The following should be used for linking to other resources for the same issue. -->
<xs:element name="Alternatives" type="altIDs" minOccurs="0" />
</xs:sequence>
<xs:complexType name="urlType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="primary" type="xs:boolean" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>

<xs:complexType name="altIDs">
<xs:complexType name="idsType">
<xs:sequence>
<xs:element name="Alternative" type="sourceType" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="ID" type="idType" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
<xs:assert test="count(ID[@primary = true()]) &lt;= 1" />
</xs:complexType>

<xs:complexType name="sourceType">
<xs:complexType name="idType">
<xs:simpleContent>
<xs:extension base="xs:positiveInteger">
<xs:attribute name="source" type="informationSource" use="required" />
<xs:attribute name="primary" type="xs:boolean" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Expand Down
20 changes: 8 additions & 12 deletions drafts/v1.0/Sample.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<MetronInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="MetronInfo.xsd">
<ID>
<Primary source="Metron">290431</Primary>
<Alternatives>
<Alternative source="Comic Vine">12345</Alternative>
<Alternative source="Grand Comics Database">543</Alternative>
</Alternatives>
</ID>
<IDS>
<ID source="Metron" primary="true">290431</ID>
<ID source="Comic Vine">12345</ID>
<ID source="Grand Comics Database">543</ID>
</IDS>
<Publisher id="12345">
<Name>DC Comics</Name>
<Imprint id="1234">Vertigo</Imprint>
Expand Down Expand Up @@ -95,11 +93,9 @@
<Reprint>Foo Bar #002 (2022)</Reprint>
</Reprints>
<URLs>
<Primary>https://comicvine.gamespot.com/justice-league-1-justice-league-part-one/4000-290431/</Primary>
<Alternatives>
<Alternative>https://foo.bar</Alternative>
<Alternative>https://bar.foo</Alternative>
</Alternatives>
<URL primary="true">https://comicvine.gamespot.com/justice-league-1-justice-league-part-one/4000-290431/</URL>
<URL>https://foo.bar</URL>
<URL>https://bar.foo</URL>
</URLs>
<Credits>
<Credit>
Expand Down

0 comments on commit dd6941c

Please sign in to comment.