title: Using owl:Class prefix with rdflib and xml serialization
body: <p>I would like to use the <code>owl:</code> prefix in the XML serialization of my RDF ontology (using rdflib version 4.1.1); unfortunately I'm still getting the serialization as <code>rdf:Description</code> tags. I have looked at the answer about binding the namespace to the graph at <a href="https://stackoverflow.com/questions/4427607/rdflib-namespace-prefixes-in-xml-serialization">RDFLib: Namespace prefixes in XML serialization</a> but this seems to only work when serializing using the <code>ns</code> format rather than <code>xml</code> format. </p>
  
  <p>Let's be more concrete. I'm attempting to get the following ontology (as taken from <a href="http://www.linkeddatatools.com/introducing-rdfs-owl" rel="nofollow noreferrer">Introducing RDFS and OWL</a>) in XML as follows:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;!-- OWL Class Definition - Plant Type --&gt;
  &lt;owl:Class rdf:about="http://www.linkeddatatools.com/plants#planttype"&gt;
  
      &lt;rdfs:label&gt;The plant type&lt;/rdfs:label&gt;
      &lt;rdfs:comment&gt;The class of all plant types.&lt;/rdfs:comment&gt;
  
  &lt;/owl:Class&gt;
  </code></pre>
  
  <p>Here is the python code for constructing such a thing, using <code>rdflib</code>: </p>
  
  <pre><code>from rdflib.namespace import OWL, RDF, RDFS
  from rdflib import Graph, Literal, Namespace, URIRef
  
  # Construct the linked data tools namespace
  LDT   = Namespace("http://www.linkeddatatools.com/plants#")
  
  # Create the graph
  graph = Graph()
  
  # Create the node to add to the Graph
  Plant = URIRef(LDT["planttype"])
  
  # Add the OWL data to the graph
  graph.add((Plant, RDF.type, OWL.Class))
  graph.add((Plant, RDFS.subClassOf, OWL.Thing))
  graph.add((Plant, RDFS.label, Literal("The plant type")))
  graph.add((Plant, RDFS.comment, Literal("The class of all plant types")))
  
  # Bind the OWL and LDT name spaces
  graph.bind("owl", OWL)
  graph.bind("ldt", LDT)
  
  print graph.serialize(format='xml')
  </code></pre>
  
  <p>Sadly, even with those bind statements, the following XML is printed:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;rdf:RDF
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
  &gt;
    &lt;rdf:Description rdf:about="http://www.linkeddatatools.com/plants#planttype"&gt;
      &lt;rdfs:subClassOf rdf:resource="http://www.w3.org/2002/07/owl#Thing"/&gt;
      &lt;rdfs:label&gt;The plant type&lt;/rdfs:label&gt;
      &lt;rdfs:comment&gt;The class of all plant types&lt;/rdfs:comment&gt;
      &lt;rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/&gt;
    &lt;/rdf:Description&gt;
  &lt;/rdf:RDF&gt;
  </code></pre>
  
  <p>Granted, this is still an Ontology, and usable - but since we have various editors, the much more compact and readable first version using the <code>owl</code> prefix would be far preferable. Is it possible to do this in <code>rdflib</code> without overriding the serialization method?</p>
  
  <p><strong>Update</strong></p>
  
  <p>In response to the comments, I'll rephrase my "bonus question" as simple clarification to my question at large.</p>
  
  <p><strong>Not a Bonus Question</strong> The topic here involves the construction of the OWL namespace formatted ontology which is a shorthand for the more verbose RDF/XML specification. The issue here is larger though than the simple declaration of a namespace prefix for shorthand for only Classes or Properties, there are many shorthand notations that have to be dealt with in code; for example <code>owl:Ontology</code> descriptions should be added as good form to this notation. I am hoping that rdflib has support for the complete specification of the notation- rather than have to roll my own serialization.</p>