I tried validating a very simple manually-written RDF online, using the W3C RDF Validator. To my surprise, it correctly resolved the URIs from the rdf namespace, but not from a different namespace (also from W3C). Why did this happen?
Let's take the example of
<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:org="http://www.w3.org/ns/org#" >
<rdf:Description rdf:about="https://stackexchange.com/">
<rdf:type rdf:resource="org:Organization"/>
</rdf:Description>
</rdf:RDF>
This validates, and gets parsed to
As you can see, the predicate (rdf:type) gets nicely expanded, and one can click on it. The object (org:Organization) doesn't get expanded at all, and also when I try clicking the link, it literally sends "org:Organization" to the browser, producing an error. But the namespace org has been defined just like the rdf namespace, and if I manually visit http://www.w3.org/ns/org#Organization, I get a Turtle document.
So, my question is: why doesn't it place http://www.w3.org/ns/org#Organization in the object? What should I change for the parser to do it properly?
The RDF namespace IRI (or namespace name) is http://www.w3.org/1999/02/22-rdf-syntax-ns# and is typically used in XML with the prefix rdf although other prefix strings may be used. The RDF Vocabulary is identified by this namespace name and consists of the following names only: Syntax names — not concepts.
RDF is Written in XML RDF documents are written in XML. The XML language used by RDF is called RDF/XML. By using XML, RDF information can easily be exchanged between different types of computers using different types of operating systems and application languages.
The rdf:parseType="Collection" Attribute RDF collections are used to describe group that contains ONLY the specified members. A collection is described by the attribute rdf:parseType="Collection".
The parser is doing it properly, actually. The problem is that you are trying to use an XML namespace prefix inside an attribute value (the value of the rdf:resource
attribute), rather than as a qualifier on an actual XML element/attribute name itself (such as rdf:type
, which is an XML element name).
Put differently: you can't use XML namespaces inside string values. The parser therefore doesn't try to "expand" the namespace, instead just parses the literal string value as a URI, and since org:Organization
is in fact a syntactically legal URI, that's what it produces.
To get your desired output, you will have to write out the full IRI string, like so:
<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:org="http://www.w3.org/ns/org#" >
<rdf:Description rdf:about="https://stackexchange.com/">
<rdf:type rdf:resource="http://www.w3.org/ns/org#Organization"/>
</rdf:Description>
</rdf:RDF>
or if you like, you can use abbreviated RDF/XML syntax, to get this:
<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:org="http://www.w3.org/ns/org#" >
<org:Organization rdf:about="https://stackexchange.com/" />
</rdf:RDF>
As an aside: RDF/XML is a notoriously tricky syntax to work with. There are other, far easier syntax formats for RDF, like for example Turtle. Just sayin'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With