Why doesn't clojure.data.xml return xml namespaces when parsing a RDF file?
Asked Answered
I

1

7

I'm working on a semantic web library for clojure and I wanted to check if data.xml returns XML namespaces for the document being parsed, so I threw together a quick program that parsed this RDF document from W3Schools RDF tutorial

<?xml version="1.0"?>

<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:cd="http://www.recshop.fake/cd#">

<rdf:Description
rdf:about="http://www.recshop.fake/cd/Empire Burlesque">
  <cd:artist>Bob Dylan</cd:artist>
  <cd:country>USA</cd:country>
  <cd:company>Columbia</cd:company>
  <cd:price>10.90</cd:price>
  <cd:year>1985</cd:year>
</rdf:Description>

<rdf:Description
rdf:about="http://www.recshop.fake/cd/Hide your heart">
  <cd:artist>Bonnie Tyler</cd:artist>
  <cd:country>UK</cd:country>
  <cd:company>CBS Records</cd:company>
  <cd:price>9.90</cd:price>
  <cd:year>1988</cd:year>
</rdf:Description>
</rdf:RDF>

And I got this. (Formatted for easier reading.)

{:tag :RDF, 
 :attrs {},
 :content ({:tag :Description, 
            :attrs {:rdf/about "http://www.recshop.fake/cd/Empire Burlesque"},
            :content ({:tag :artist,
                       :attrs {},
                       :content ("Bob Dylan")}
                      {:tag :country, 
                       :attrs {},
                       :content ("USA")}
                      {:tag :company,
                       :attrs {},
                       :content ("Columbia")}
                      {:tag :price, 
                       :attrs {},
                       :content ("10.90")}
                      {:tag :year,
                       :attrs {},
                       :content ("1985")})}
           {:tag :Description, 
            :attrs {:rdf/about "http://www.recshop.fake/cd/Hide your heart"},
            :content ({:tag :artist,
                       :attrs {},
                       :content ("Bonnie Tyler")}
                      {:tag :country,
                       :attrs {},
                       :content ("UK")}
                      {:tag :company,
                       :attrs {},
                       :content ("CBS Records")}
                      {:tag :price,
                       :attrs {},
                       :content ("9.90")}
                      {:tag :year,
                      :attrs {},
                      :content ("1988")})})}

So if I wanted to create triples from the parsed document, I couldn't, because the parsers in data.xml don't don't return namespaces from the root of a document. Why is that?

Imponderable answered 13/2, 2014 at 1:33 Comment(3)
The short answer is that clojure.data.xml's design is deficient in this respect.Hansiain
There is some discussion about this here and here (with some unfinished attempts made). I too need xmlns support for XML in Clojure.Impair
Here's the ticket for the still-unmerged namespace support: dev.clojure.org/jira/browse/DXML-4Buoyancy
M
1

clojure.data.xml now supports this, but at the time this question was asked it did not.

Support for namespaces was introduced in 0.1.0-beta1 (January 2016), and as we are now up to 0.2.0-beta5 it is safe to say that it is fairly established and battle-tested.

Maui answered 27/4, 2018 at 11:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.