nasar2016 / rdfquery

Automatically exported from code.google.com/p/rdfquery
0 stars 0 forks source link

RDF/XML lang tags apply improperly to subsequent siblings #25

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
When parsing RDF/XML with lang tags, the language is applied to all subsequent
literals at the same level.  E.g. in the following RDF/XML taken from
a geonames response:

    var xml = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>'
        + '<rdf:RDF xmlns:cc="http://creativecommons.org/ns#" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:gn="http://www.geonames.org/ontology#" xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:wgs84_pos="http://www.w3.org/2003/01/geo/wgs84_pos#">'
        + '<gn:Feature rdf:about="http://sws.geonames.org/2950159/">'
        + '<rdfs:isDefinedBy>http://sws.geonames.org/2950159/about.rdf</rdfs:isDefinedBy>'
        + '<gn:name>Berlin</gn:name>'
        + '<gn:alternateName xml:lang="es">Berlín</gn:alternateName>'
        + '<wgs84_pos:lat>52.52437</wgs84_pos:lat>'
        + '</gn:Feature>'
        + '</rdf:RDF>';

the lang "es" for gn:alternateName tag is also applied to the
wgs84_pos:lat lattitude.  I'm pretty sure this is not the right thing
to do.

The following patch, made against rdfquery 1.0 fixes it for me:

diff --git a/jquery.rdf.js b/jquery.rdf.js
index 8c21af0..473fe86 100644
--- a/jquery.rdf.js
+++ b/jquery.rdf.js
@@ -675,6 +675,7 @@
           }
         }
       }
+      var parentLang = lang;
       for (i = 0; i < elem.childNodes.length; i += 1) {
         p = elem.childNodes[i];
         if (p.nodeType === 1) {
@@ -684,9 +685,11 @@
           } else {
             property = $.rdf.resource('<' + p.namespaceURI + getLocalName(p) + '>');
           }
-          lang = getAttributeNS(p, 'http://www.w3.org/XML/1998/namespace', 
'lang') || lang;
+          lang = getAttributeNS(p, 'http://www.w3.org/XML/1998/namespace', 
'lang') || parentLang;
           if (lang !== null && lang !== undefined && lang !== '') {
             literalOpts = { lang: lang };
+          } else {
+            literalOpts = {};
           }
           if (hasAttributeNS(p, rdfNs, 'resource')) {
             o = getAttributeNS(p, rdfNs, 'resource');

Original issue reported on code.google.com by d.j.lamb...@gmail.com on 13 Oct 2010 at 9:20

GoogleCodeExporter commented 8 years ago
Applied patch

Original comment by d.j.lamb...@gmail.com on 30 Nov 2010 at 2:26