2

I'm using python's rdflib package to parse RDF xml as triples. I am comparing multiple files, and I want to be able to check that the base URI defined in the <rdf:RDF> tag as xml:base is the same accross two files.

My code for reading in the libary is as follows:

import rdflib

g = rdflib.Graph()
g.load("some_file.xml")

In the above code, g contains a graph of RDF subject-predicate-object triplets that I can iterate over and do work with.

I can get out the namespace elements denoted by xmlns:... using g.namespaces().

Say the contents of some_file.xml are as follows:

<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
  xmlns:cims="http://iec.ch/TC57/1999/rdf-schema-extensions-19990926#"
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
  xmlns:cim="http://iec.ch/TC57/2013/CIM-schema-cim16#"
  xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
  xml:base="http://iec.ch/TC57/2013/CIM-schema-cim16">
  <rdf:Description rdf:about="#Package_newprofile">
    <rdfs:label xml:lang="en">newprofile</rdfs:label>
    <rdf:type rdf:resource="http://iec.ch/TC57/1999/rdf-schema-extensions-19990926#ClassCategory"/>
  </rdf:Description>
  <rdf:Description rdf:about="#ACLineSegment">
    <rdfs:label xml:lang="en">ACLineSegment</rdfs:label>
    <rdfs:comment rdf:parseType="Literal">A wire or combination of wires, with consistent electrical characteristics, building a single electrical system, used to carry alternating current between points in the power system. For symmetrical, transposed
      3ph lines, it is sufficient to use attributes of the line segment, which describe impedances and admittances for the entire length of the segment. Additionally impedances can be computed by using length and associated per length impedances. The
      BaseVoltage at the two ends of ACLineSegments in a Line shall have the same BaseVoltage.nominalVoltage. However, boundary lines may have slightly different BaseVoltage.nominalVoltages and variation is allowed. Larger voltage difference in general
      requires use of an equivalent branch.</rdfs:comment>
    <cims:belongsToCategory rdf:resource="#Package_newprofile"/>
    <cims:stereotype rdf:resource="http://iec.ch/TC57/NonStandard/UML#concrete"/>
    <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/>
  </rdf:Description>
  <rdf:Description rdf:about="#ACLineSegment.r">
    <cims:stereotype rdf:resource="http://iec.ch/TC57/NonStandard/UML#attribute"/>
    <rdfs:label xml:lang="en">r</rdfs:label>
    <rdfs:domain rdf:resource="#ACLineSegment"/>
    <cims:dataType rdf:resource="#Resistance"/>
    <cims:multiplicity rdf:resource="http://iec.ch/TC57/1999/rdf-schema-extensions-19990926#M:1..1"/>
    <cims:isFixed rdfs:Literal="10"/>
    <rdfs:comment rdf:parseType="Literal">Positive sequence series resistance of the entire line section.</rdfs:comment>
    <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"/>
  </rdf:Description>
  ...
</rdf>

How do I get the xml base (i.e. the value denoted by xml:base="http://iec.ch/TC57/2013/CIM-schema-cim16"?

AnjoMan
  • 4,838
  • 4
  • 20
  • 28
  • Have you any progress on it? – Stanislav Kralin Aug 20 '17 at 19:55
  • 1
    @StanislavKralin so far, no. The best I've been able to do is just split it out from a type definition, but that seems kind of hacky to me. – AnjoMan Aug 21 '17 at 14:22
  • ОК, thank you. The only thing I have figured out is that one can set `xml:base` using `publicID` argument in [`Graph.parse()`](https://rdflib.readthedocs.io/en/stable/apidocs/rdflib.html#rdflib.graph.Graph.parse), if `xml:base` is absent. However, one can not override `xml:base`in this way. – Stanislav Kralin Aug 21 '17 at 14:36

0 Answers0