Skip to content

Commit

Permalink
Adding more of the namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
klakegg committed Oct 3, 2023
1 parent da57473 commit 435f26c
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 22 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build:
@go build .

test:
@go test -v
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# go-genericode

Partial implementation of [Code List Representation (genericode) Version 1.0](http://docs.oasis-open.org/codelist/genericode/doc/oasis-code-list-representation-genericode.html).
Partial implementation of [Code List Representation (genericode) Version 1.0](http://docs.oasis-open.org/codelist/genericode/doc/oasis-code-list-representation-genericode.html).

Focus of implementation is limited to code list part of the standard and skipping elements supporting XML not part of genericode (i.e. `Annotation` and `ComplexValue`).
77 changes: 56 additions & 21 deletions namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ import (
"encoding/xml"
)

type Genericode struct {
}

type CodeList struct {
XMLName xml.Name `xml:"http://docs.oasis-open.org/codelist/ns/genericode/1.0/ CodeList"`
Identification *Identification
Columns []*Column `xml:"ColumnSet>Column"`
Keys []*Key `xml:"ColumnSet>Key"`
Rows []*Row `xml:"SimpleCodeList>Row"`
Genericode

XMLName xml.Name `xml:"http://docs.oasis-open.org/codelist/ns/genericode/1.0/ CodeList"`
Identification *Identification `xml:"Identification"`
Columns []*Column `xml:"ColumnSet>Column"`
Keys []*Key `xml:"ColumnSet>Key"`
Rows []*Row `xml:"SimpleCodeList>Row"`

columnIndex map[string]*Column
keyIndex map[string]*Key
Expand All @@ -31,36 +36,52 @@ func (cl *CodeList) Column(id string) *Column {
}

type Identification struct {
ShortName []ShortName `xml:"ShortName"`
Version *string `xml:"Version"`
CanonicalUri *string `xml:"CanonicalUri"`
CanonicalVersionUri *string `xml:"CanonicalVersionUri"`
ShortName *TranslatableName `xml:"ShortName"`
LongName []*TranslatableName `xml:"LongName"`
Version *string `xml:"Version"`
CanonicalUri *string `xml:"CanonicalUri"`
CanonicalVersionUri *string `xml:"CanonicalVersionUri"`
LocationUri *string `xml:"LocationUri"`
AlternateFormatLocationUri *MimeTypedUri `xml:"AlternateFormatLocationUri"`
Agency *Agency `xml:"Agency"`
}

type Agency struct {
ShortName *TranslatableName `xml:"ShortName"`
LongName *[]TranslatableName `xml:"LongName"`
Identifier *[]string `xml:"Identifier"`
}

type Column struct {
Id *string `xml:"Id,attr"`
Use *string `xml:"Use,attr"`
ShortName []*ShortName `xml:"ShortName"`
Data *Data `xml:"Data"`
Id *string `xml:"Id,attr"` // Required
Use *string `xml:"Use,attr"` // Required
ShortName *TranslatableName `xml:"ShortName"`
LongName []*TranslatableName `xml:"LongName"`
CanonicalUri *string `xml:"CanonicalUri"`
CanonicalVersionUri *string `xml:"CanonicalVersionUri"`
Data *Data `xml:"Data"` // Required

codeList *CodeList
}

type Key struct {
Id *string `xml:"Id,attr"`
ShortName []*ShortName `xml:"ShortName"`
ColumnRef ColumnRef `xml:"ColumnRef"`
Id *string `xml:"Id,attr"` // Required
ShortName *TranslatableName `xml:"ShortName"`
LongName []*TranslatableName `xml:"LongName"`
CanonicalUri *string `xml:"CanonicalUri"`
CanonicalVersionUri *string `xml:"CanonicalVersionUri"`
ColumnRef *[]ColumnRef `xml:"ColumnRef"` // Required

codeList *CodeList
}

type Row struct {
Values []Value `xml:"Value"`
Values []*Value `xml:"Value"`
}

func (row *Row) Get(key string) *string {
func (row *Row) Get(column string) *string {
for _, value := range row.Values {
if *value.ColumnRef == key {
if *value.ColumnRef == column {
return value.Value
}
}
Expand All @@ -73,15 +94,29 @@ type Value struct {
Value *string `xml:"SimpleValue"`
}

type ShortName struct {
type TranslatableName struct {
Value string `xml:",chardata"`
Language *string `xml:"lang,attr"`
}

type Data struct {
Type *string `xml:"Type,attr"`
Type *string `xml:"Type,attr"`
DatatypeLibrary *string `xml:"DatatypeLibrary,attr"`
Language *string `xml:"Lang,attr"`
Parameter *[]DatatypeFacet `xml:"Parameter"`
}

type DatatypeFacet struct {
Facet string `xml:",chardata"` // Required
ShortName *string `xml:"ShortName,attr"` // Required
LongName *string `xml:"LongName,attr"`
}

type ColumnRef struct {
Ref *string `xml:"Ref,attr"`
}

type MimeTypedUri struct {
URI string `xml:",chardata"` // Required
MimeType *string `xml:"MimeType,attr"`
}

0 comments on commit 435f26c

Please sign in to comment.