using the xml package with data with complex name spacing

129 views
Skip to first unread message

Dan Kortschak

unread,
Dec 13, 2020, 5:27:01 PM12/13/20
to golang-nuts
I'm needing to consume some XML which has a namespace identifier
reused.

<rdf:RDF xmlns="http://purl.obolibrary.org/obo/go/subsets/goslim_yeast.owl#"
xml:base="http://purl.obolibrary.org/obo/go/subsets/goslim_yeast.owl"
xmlns:go="http://purl.obolibrary.org/obo/go#"
xmlns:obo="http://purl.obolibrary.org/obo/"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:terms="http://www.geneontology.org/formats/oboInOwl#http://purl.org/dc/terms/"
xmlns:oboInOwl="http://www.geneontology.org/formats/oboInOwl#">;
<owl:Ontology rdf:about="http://purl.obolibrary.org/obo/go/subsets/goslim_yeast.owl">;
<owl:versionIRI rdf:resource="http://purl.obolibrary.org/obo/go/2020-12-08/subsets/goslim_yeast.owl"/>;
</owl:Ontology>

<!-- much more data -->

</rdf:RDF>


I'm wondering if I can do this with out directly interacting with a
token stream.

https://play.golang.org/p/5y0LGh-MbGE

thanks


Sam Whited

unread,
Dec 14, 2020, 8:54:45 AM12/14/20
to golan...@googlegroups.com
In the example you provided it is working as expected. The element
you're unmarshaling is in the "
http://www.w3.org/1999/02/22-rdf-syntax-ns#" namespace (it has an "rdf"
prefix) but the thing you're unmarshaling it into expects
"http://purl.obolibrary.org/obo/go/subsets/goslim_yeast.owl#" because you
put that in the tag.

If you change the namespace in the struct to the correct one everything will work.

—Sam

Dan Kortschak

unread,
Dec 14, 2020, 2:40:39 PM12/14/20
to golan...@googlegroups.com
On Mon, 2020-12-14 at 13:53 +0000, Sam Whited wrote:
> In the example you provided it is working as expected. The element
> you're unmarshaling is in the "
> http://www.w3.org/1999/02/22-rdf-syntax-ns#" namespace (it has an
> "rdf"
> prefix) but the thing you're unmarshaling it into expects
> "http://purl.obolibrary.org/obo/go/subsets/goslim_yeast.owl#" because
> you
> put that in the tag.
>
> If you change the namespace in the struct to the correct one
> everything will work.
>
> —Sam

Thanks, Sam. I figured it would be something simple like that.

I ended up skirting the issue; I do start with parsing the token stream
and then using the Decoder.DecodeElement on specific start elements
(for reasons entirely unrelated to the original questions).

Dan


Reply all
Reply to author
Forward
0 new messages