W3C home > Mailing lists > Public > semantic-web@w3.org > September 2005

rdflib lang:xml attribute on properties

From: David Pratt <fairwinds@eastlink.ca>
Date: Thu, 08 Sep 2005 09:58:01 -0300
To: semantic-web@w3.org
Message-id: <3007D2C2-2068-11DA-B91E-000A27B3B070@eastlink.ca>

Hi. I am using python rdflib.  I have contacted the author of the 
software but no response to query of how to add lang attribute to 
properties on adding data to store. Anyone with any experience with 
rdflib to provide any pointers. There is an api but few examples and 
googling very little by the way of discussions, lists etc for the 
library or rdf xml in general.  Anyone using rdflib that can give me a 

An example of the library is below that came with the library.  I am 
assuming there is a way to specify the languages on a property or 
literal so that when serialized with give me something like this for 
example <foaf:nick xml:lang="en">donna</foaf:nick> and when converted 
to raw triples with give me donna@en.

# Create a namespace object for the Friend of a friend namespace.
FOAF = Namespace("http://xmlns.com/foaf/0.1/")

# Create an identifier to use as the subject for Donna.
donna = BNode()

# Add triples using store's add method.
store.add((donna, RDF.type, FOAF["Person"]))
store.add((donna, FOAF["nick"], Literal("donna")))
store.add((donna, FOAF["name"], Literal("Donna Fales")))

# Serialize the store as RDF/XML to the file foaf.rdf.
store.save("foaf.rdf", format="pretty-xml")

Serializing produces:

<?xml version="1.0" encoding="utf-8"?>
     <foaf:name>Donna Fales</foaf:name>

Received on Thursday, 8 September 2005 12:58:21 UTC

This archive was generated by hypermail 2.4.0 : Tuesday, 5 July 2022 08:44:54 UTC