blob: 9a6ce6df21846503e641f6375db2c971590255cc [file] [log] [blame]
<!DOCTYPE html>
<html lang="en">
<head>
<title>Apache Jena - Jena RDF/XML How-To</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="/css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="/css/bootstrap-icons.css" rel="stylesheet" media="screen"><link rel="stylesheet" type="text/css" href="https://jena.apache.org/sass/jena.1b17c39a117e22b46db4c66f6395dc27c134a60377d87d2d5745b8600eb69722.css" integrity="sha256-GxfDmhF&#43;IrRttMZvY5XcJ8E0pgN32H0tV0W4YA62lyI=">
<link rel="shortcut icon" href="/images/favicon.ico" />
</head>
<body>
<nav class="navbar navbar-expand-lg bg-body-tertiary" role="navigation">
<div class="container">
<div class="navbar-header">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="/index.html">
<img class="logo-menu" src="/images/jena-logo/jena-logo-notext-small.png" alt="jena logo">Apache Jena</a>
</div>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li id="homepage" class="nav-item"><a class="nav-link" href="/index.html"><span class="bi-house"></span> Home</a></li>
<li id="download" class="nav-item"><a class="nav-link" href="/download/index.cgi"><span class="bi-download"></span> Download</a></li>
<li class="nav-item dropdown">
<a href="#" class="nav-link dropdown-toggle" role="button" data-bs-toggle="dropdown" aria-expanded="false"><span class="bi-journal"></span> Learn <b class="caret"></b></a>
<ul class="dropdown-menu">
<li class="dropdown-header">Tutorials</li>
<li><a class="dropdown-item" href="/tutorials/index.html">Overview</a></li>
<li><a class="dropdown-item" href="/documentation/fuseki2/index.html">Fuseki Triplestore</a></li>
<li><a class="dropdown-item" href="/documentation/notes/index.html">How-To's</a></li>
<li><a class="dropdown-item" href="/documentation/query/manipulating_sparql_using_arq.html">Manipulating SPARQL using ARQ</a></li>
<li><a class="dropdown-item" href="/tutorials/rdf_api.html">RDF core API tutorial</a></li>
<li><a class="dropdown-item" href="/tutorials/sparql.html">SPARQL tutorial</a></li>
<li><a class="dropdown-item" href="/tutorials/using_jena_with_eclipse.html">Using Jena with Eclipse</a></li>
<li class="dropdown-divider"></li>
<li class="dropdown-header">References</li>
<li><a class="dropdown-item" href="/documentation/index.html">Overview</a></li>
<li><a class="dropdown-item" href="/documentation/query/index.html">ARQ (SPARQL)</a></li>
<li><a class="dropdown-item" href="/documentation/io/">RDF I/O</a></li>
<li><a class="dropdown-item" href="/documentation/assembler/index.html">Assembler</a></li>
<li><a class="dropdown-item" href="/documentation/tools/index.html">Command-line tools</a></li>
<li><a class="dropdown-item" href="/documentation/rdfs/">Data with RDFS Inferencing</a></li>
<li><a class="dropdown-item" href="/documentation/geosparql/index.html">GeoSPARQL</a></li>
<li><a class="dropdown-item" href="/documentation/inference/index.html">Inference API</a></li>
<li><a class="dropdown-item" href="/documentation/ontology/">Ontology API</a></li>
<li><a class="dropdown-item" href="/documentation/permissions/index.html">Permissions</a></li>
<li><a class="dropdown-item" href="/documentation/extras/querybuilder/index.html">Query Builder</a></li>
<li><a class="dropdown-item" href="/documentation/rdf/index.html">RDF API</a></li>
<li><a class="dropdown-item" href="/documentation/rdfconnection/">RDF Connection - SPARQL API</a></li>
<li><a class="dropdown-item" href="/documentation/rdfstar/index.html">RDF-star</a></li>
<li><a class="dropdown-item" href="/documentation/shacl/index.html">SHACL</a></li>
<li><a class="dropdown-item" href="/documentation/shex/index.html">ShEx</a></li>
<li><a class="dropdown-item" href="/documentation/tdb/index.html">TDB</a></li>
<li><a class="dropdown-item" href="/documentation/tdb2/index.html">TDB2</a></li>
<li><a class="dropdown-item" href="/documentation/query/text-query.html">Text Search</a></li>
</ul>
</li>
<li class="nav-item dropdown">
<a href="#" class="nav-link dropdown-toggle" role="button" data-bs-toggle="dropdown" aria-expanded="false"><span class="bi-journal-code"></span> Javadoc <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="/documentation/javadoc.html">All Javadoc</a></li>
<li><a class="dropdown-item" href="/documentation/javadoc/arq/">ARQ</a></li>
<li><a class="dropdown-item" href="/documentation/javadoc/fuseki2/">Fuseki</a></li>
<li><a class="dropdown-item" href="/documentation/javadoc/geosparql/">GeoSPARQL</a></li>
<li><a class="dropdown-item" href="/documentation/javadoc/jena/">Jena Core</a></li>
<li><a class="dropdown-item" href="/documentation/javadoc/permissions/">Permissions</a></li>
<li><a class="dropdown-item" href="/documentation/javadoc/extras/querybuilder/">Query Builder</a></li>
<li><a class="dropdown-item" href="/documentation/javadoc/shacl/">SHACL</a></li>
<li><a class="dropdown-item" href="/documentation/javadoc/tdb/">TDB</a></li>
<li><a class="dropdown-item" href="/documentation/javadoc/text/">Text Search</a></li>
</ul>
</li>
</ul>
<form class="d-flex" role="search" action="/search" method="GET">
<div class="input-group">
<input class="form-control border-end-0 border m-0" type="search" name="q" id="search-query" placeholder="Search...." aria-label="Search" style="width: 10rem;">
<button class="btn btn-outline-secondary border-start-0 border" type="submit">
<i class="bi-search"></i>
</button>
</div>
</form>
<ul class="navbar-nav">
<li id="ask" class="nav-item"><a class="nav-link" href="/help_and_support/index.html" title="Ask"><span class="bi-patch-question"></span><span class="text-body d-none d-xxl-inline"> Ask</span></a></li>
<li class="nav-item dropdown">
<a href="#" title="Get involved" class="nav-link dropdown-toggle" role="button" data-bs-toggle="dropdown" aria-expanded="false"><span class="bi-megaphone"></span><span class="text-body d-none d-xxl-inline"> Get involved </span><b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="/getting_involved/index.html">Contribute</a></li>
<li><a class="dropdown-item" href="/help_and_support/bugs_and_suggestions.html">Report a bug</a></li>
<li class="dropdown-divider"></li>
<li class="dropdown-header">Project</li>
<li><a class="dropdown-item" href="/about_jena/about.html">About Jena</a></li>
<li><a class="dropdown-item" href="/about_jena/architecture.html">Architecture</a></li>
<li><a class="dropdown-item" href="/about_jena/citing.html">Citing</a></li>
<li><a class="dropdown-item" href="/about_jena/team.html">Project team</a></li>
<li><a class="dropdown-item" href="/about_jena/contributions.html">Related projects</a></li>
<li><a class="dropdown-item" href="/about_jena/roadmap.html">Roadmap</a></li>
<li><a class="dropdown-item" href="/about_jena/security-advisories.html">Security Advisories</a></li>
<li class="dropdown-divider"></li>
<li class="dropdown-header">ASF</li>
<li><a class="dropdown-item" href="https://www.apache.org/">Apache Software Foundation</a></li>
<li><a class="dropdown-item" href="https://www.apache.org/foundation/sponsorship.html">Become a Sponsor</a></li>
<li><a class="dropdown-item" href="https://www.apache.org/licenses/LICENSE-2.0">License</a></li>
<li><a class="dropdown-item" href="https://www.apache.org/security/">Security</a></li>
<li><a class="dropdown-item" href="https://www.apache.org/foundation/thanks.html">Thanks</a></li>
</ul>
</li>
<li class="nav-item" id="edit"><a class="nav-link" href="https://github.com/apache/jena-site/edit/main/source/documentation/io/rdfxml_howto.md" title="Edit this page on GitHub"><span class="bi-pencil-square"></span><span class="text-body d-none d-xxl-inline"> Edit this page</span></a></li>
</ul>
</div>
</div>
</nav>
<div class="container">
<div class="row">
<div class="col-md-12">
<div id="breadcrumbs">
<ol class="breadcrumb mt-4 p-2 bg-body-tertiary">
<li class="breadcrumb-item"><a href='/documentation'>DOCUMENTATION</a></li>
<li class="breadcrumb-item"><a href='/documentation/io'>IO</a></li>
<li class="breadcrumb-item active">RDFXML HOWTO</li>
</ol>
</div>
<h1 class="title">Jena RDF/XML How-To</h1>
<main class="d-flex flex-xl-row flex-column">
<aside class="text-muted align-self-start mb-3 p-0 d-xl-none d-block">
<h2 class="h6 sticky-top m-0 p-2 bg-body-tertiary">On this page</h2>
<nav id="TableOfContents">
<ul>
<li><a href="#quick-introduction">Quick Introduction</a></li>
<li><a href="#rdfxml-rdfxml-abbrev">RDF/XML, RDF/XML-ABBREV</a></li>
<li><a href="#character-encoding-issues">Character Encoding Issues</a>
<ul>
<li><a href="#encodings-supported-in-jena-22-and-later">Encodings Supported in Jena 2.2 and later</a></li>
</ul>
</li>
<li><a href="#when-to-use-reader-and-writer">When to Use Reader and Writer?</a></li>
<li><a href="#introduction-to-advanced-jena-io">Introduction to Advanced Jena I/O</a></li>
<li><a href="#advanced-rdfxml-input">Advanced RDF/XML Input</a>
<ul>
<li><a href="#arp-properties">ARP properties</a></li>
<li><a href="#interrupting-arp">Interrupting ARP</a></li>
</ul>
</li>
<li><a href="#advanced-rdfxml-output">Advanced RDF/XML Output</a>
<ul>
<li><a href="#properties-to-control-rdfxml-output">Properties to Control RDF/XML Output</a></li>
</ul>
</li>
<li><a href="#conformance">Conformance</a></li>
<li><a href="#faster-rdfxml-io">Faster RDF/XML I/O</a></li>
</ul>
</nav>
</aside>
<article class="flex-column me-lg-4">
<p><em>Legacy Documentation : may not be up-to-date</em></p>
<ul>
<li>The original ARQ parser will be removed from Jena. *</li>
</ul>
<hr>
<p>This is a guide to the RDF/XML I/O subsystem of Jena, ARP.
The first section gives a quick introduction to the
I/O subsystem. The other sections are aimed at users wishing to use
advanced features within the RDF/XML I/O subsystem.</p>
<p>Other content related to Jena RDF/XML How-To includes:</p>
<ul>
<li><a href="arp.html">Details of ARP, the Jena RDF/XML parser</a></li>
</ul>
<h2 id="quick-introduction">Quick Introduction</h2>
<p>The main I/O methods in Jena use <code>InputStream</code>s and <code>OutputStream</code>s.
This is import to correctly handle character sets.</p>
<p>These methods are found on the
<a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/Model.html"><code>Model</code></a> interface.
These are:</p>
<ul>
<li><a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/Model.html"><code>Model</code></a> [<code>read</code>](/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/Model.html#read(java.io.InputStream, java.lang.String))<code>(java.io.InputStream in, java.lang.String base)</code>
<br />Add statements from an RDF/XML serialization</li>
<li><a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/Model.html"><code>Model</code></a> [<code>read</code>](/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/Model.html#read(java.io.InputStream, java.lang.String, java.lang.String))<code>(java.io.InputStream in, java.lang.String base, java.lang.String lang)</code>
<br /> Add RDF statements represented in language <code>lang</code> to the model.</li>
<li><a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/Model.html"><code>Model</code></a> <a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/Model.html#read(java.lang.String)"><code>read</code></a><code>(java.lang.String url)</code>
<br />Add the RDF statements from an XML document.</li>
<li><a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/Model.html"><code>Model</code></a> <a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/Model.html#write(java.io.OutputStream)"><code>write</code></a><code>(java.io.OutputStream out)</code>
<br /> Write the model as an XML document.</li>
<li><a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/Model.html"><code>Model</code></a> [<code>write</code>](/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/Model.html#write(java.io.OutputStream, java.lang.String))<code>(java.io.OutputStream out, java.lang.String lang)</code>
<br />Write a serialized representation of a model in a specified language.</li>
<li><a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/Model.html"><code>Model</code></a> [<code>write</code>](/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/Model.html#write(java.io.OutputStream, java.lang.String, java.lang.String))<code>(java.io.OutputStream out, java.lang.String lang, java.lang.String base)</code>
<br />Write a serialized representation of a model in a specified language.</li>
</ul>
<p>The built-in languages are <code>&quot;RDF/XML&quot;</code>, <code>&quot;RDF/XML-ABBREV&quot;</code> as well as
<code>&quot;N-TRIPLE&quot;</code>, and <code>&quot;TURTLE&quot;</code>.</p>
<p>There are also methods which use <code>Reader</code>s and <code>Writer</code>s. Do not use
them, unless you are sure it is correct to. In advanced
applications, they are useful, see <a href="#reader-writer">below</a>; and
there is every intention to continue to support them. The RDF/XML
parser now checks to see if the <code>Model.read(Reader …)</code> calls
are being abused, and issues
<a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdfxml/xmlinput/ARPErrorNumbers.html#ERR_ENCODING_MISMATCH"><code>ERR_ENCODING_MISMATCH</code></a>
and
<a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdfxml/xmlinput/ARPErrorNumbers.html#WARN_ENCODING_MISMATCH"><code>WARN_ENCODING_MISMATCH</code></a>
errors. Most incorrect usage of <code>Reader</code>s for RDF/XML input will
result in such errors. Most incorrect usage of <code>Writer</code>s for RDF/XML
output will produce correct XML by using an appropriate XML
declaration giving the encoding - e.g.</p>
<pre><code>&lt;?xml version='1.0' encoding='ISO-8859-15'?&gt;
</code></pre>
<p>However, such XML is less portable than XML in UTF-8. Using the
<code>Model.write(OutputStream …)</code> methods allows the Jena system
code to choose UTF-8 encoding, which is the best choice.</p>
<h2 id="rdfxml-rdfxml-abbrev">RDF/XML, RDF/XML-ABBREV</h2>
<p>For input, both of these are the same, and fully implement the
<a href="http://www.w3.org/TR/rdf-syntax-grammar/">RDF Syntax Recommendation</a>,
see <a href="#conformance">conformance</a>.</p>
<p>For output, <code>&quot;RDF/XML&quot;</code>, produces regular output reasonably
efficiently, but it is not readable. In contrast,
<code>&quot;RDF/XML-ABBREV&quot;</code>, produces readable output without much regard to
efficiency.</p>
<p>All the readers and writers for RDF/XML are configurable, see
below, <a href="#input">input</a> and <a href="#output">output</a>.</p>
<h2 id="character-encoding-issues">Character Encoding Issues</h2>
<p>The easiest way to not read or understand this section is always to
use <code>InputStream</code>s and <code>OutputStream</code>s with Jena, and to never use
<code>Reader</code>s and <code>Writer</code>s. If you do this, Jena will do the right thing,
for the vast majority of users. If you have legacy code that uses
<code>Reader</code>s and <code>Writer</code>s, or you have special needs with respect to
encodings, then this section may be helpful. The last part of this
section summarizes the character encodings supported by Jena.</p>
<p>Character encoding is the way that characters are mapped to bytes,
shorts or ints. There are many different character encodings.
Within Jena, character encodings are important in their
relationship to Web content, particularly RDF/XML files, which
cannot be understood without knowing the character encoding, and in
relationship to Java, which provides support for many character
encodings.</p>
<p>The Java approach to encodings is designed for ease of use on a
single machine, which uses a single encoding; often being a
one-byte encoding, e.g. for European languages which do not need
thousands of different characters.</p>
<p>The XML approach is designed for the Web which uses multiple
encodings, and some of them requiring thousands of characters.</p>
<p>On the Web, XML files, including RDF/XML files, are by default
encoded in &ldquo;UTF-8&rdquo; (Unicode). This is always a good choice for
creating content, and is the one used by Jena by default. Other
encodings can be used, but may be less interoperable. Other
encodings should be named using the canonical name registered at
<a href="http://www.iana.org/assignments/character-sets">IANA</a>, but other
systems have no obligations to support any of these, other than
UTF-8 and UTF-16.</p>
<p>Within Java, encodings appear primarily with the <code>InputStreamReader</code>
and <code>OutputStreamWriter</code> classes, which convert between bytes and
characters using a named encoding, and with their subclasses,
<code>FileReader</code> and <code>FileWriter</code>, which convert between bytes in the file
and characters using the default encoding of the platform. It is
not possible to change the encoding used by a <code>Reader</code> or <code>Writer</code>
while it is being used. The default encoding of the platform
depends on a large range of factors. This default encoding may be
useful for communicating with other programs on the same platform.
Sometimes the default encoding is not registered at IANA, and so
Jena application developers should not use the default encoding for
Web content, but use UTF-8.</p>
<h3 id="encodings-supported-in-jena-22-and-later">Encodings Supported in Jena 2.2 and later</h3>
<p>On RDF/XML input any encoding supported by Java can be used. If
this is not a canonical name registered at IANA a warning message
is produced. Some encodings have better support in Java 1.5 than
Java 1.4; for such encodings a warning message is produced on Java
1.4, suggesting upgrading.</p>
<p>On RDF/XML output any encoding supported by Java can be used, by
constructing an <code>OutputStreamWriter</code> using that encoding, and using
that for output. If the encoding is not registered at IANA then a
warning message is produced. Some encodings have better support in
Java 1.5 than Java 1.4; for such encodings a warning message is
produced on Java 1.4, suggesting upgrading.</p>
<p>Java can be configured either with or without a jar of extra
encodings on the classpath. This jar is <code>charsets.jar</code> and sits in
the <code>lib</code> directory of the Java Runtime. If this jar is not on your
classpath then the range of encodings supported is fairly small.</p>
<p>The encodings supported by Java are listed by Sun, for
<a href="http://docs.oracle.com/javase/1.4.2/docs/guide/intl/encoding.doc.html">1.4.2</a>,
and
<a href="http://docs.oracle.com/javase/1.5.0/docs/guide/intl/encoding.doc.html">1.5.0</a>.
For an encoding that is not in these lists it is possible to write
your own transcoder as documented in the <code>java.nio.charset</code> package
documentation.</p>
<p>Earlier versions of Jena supported fewer encodings.</p>
<h2 id="when-to-use-reader-and-writer">When to Use Reader and Writer?</h2>
<p>Infrequently.</p>
<p>Despite the character encoding issues, it is still sometimes
appropriate to use <code>Reader</code>s and <code>Writer</code>s with Jena I/O. A good
example is using <code>Reader</code>s and <code>Writer</code>s into <code>StringBuffer</code>s in memory.
These do not need to be encoded and decoded so a character encoding
does not need to be specified. Other examples are when an advanced
user explicitly wishes to correctly control the encoding.</p>
<ul>
<li><a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/Model.html"><code>Model</code></a> [<code>read</code>](/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/Model.html#read(java.io.Reader, java.lang.String))<code>(java.io.Reader reader, java.lang.String base)</code>
<br />Using this method is often a mistake.</li>
<li><a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/Model.html"><code>Model</code></a> [<code>read</code>](/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/Model.html#read(java.io.Reader, java.lang.String, java.lang.String))<code>(java.io.Reader reader, java.lang.String base, java.lang.String lang)</code>
<br />Using this method is often a mistake.</li>
<li><a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/Model.html"><code>Model</code></a> <a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/Model.html#write(java.io.Writer)"><code>write</code></a><code>(java.io.Writer writer)</code>
<br />Caution! Write the model as an XML document.</li>
<li><a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/Model.html"><code>Model</code></a> [<code>write</code>](/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/Model.html#write(java.io.Writer, java.lang.String))<code>(java.io.Writer writer, java.lang.String lang)</code>
<br /> Caution! Write a serialized representation of a model in a specified language.</li>
<li><a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/Model.html"><code>Model</code></a> [<code>write</code>](/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/Model.html#write(java.io.Writer, java.lang.String, java.lang.String))<code>(java.io.Writer writer, java.lang.String lang, java.lang.String base)</code>
<br /> Caution! Write a serialized representation of a model in a specified language.</li>
</ul>
<p>Incorrect use of these <code>read(Reader, …)</code> methods results in
warnings and errors with RDF/XML and RDF/XML-ABBREV (except in a
few cases where the incorrect use cannot be automatically
detected). Incorrect use of the <code>write(Writer, …)</code> methods
results in peculiar XML declarations such as
<code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;WINDOWS-1252&quot;?&gt;</code>. This would reflect
that the character encoding you used (probably without realizing)
in your Writer is registered with IANA under the name
&ldquo;WINDOWS-1252&rdquo;. The resulting XML is of reduced portability as a
result. Glenn Marcy
<a href="http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4456">notes</a>:</p>
<blockquote>
<p>since UTF-8 and UTF-16 are the only encodings REQUIRED to be
understood by all conformant XML processors, even ISO-8859-1 would
technically be on shaky ground if not for the fact that it is in
such widespread use that every reasonable XML processor supports
it.With N-TRIPLE incorrect use is usually benign, since N-TRIPLE is
ascii based.</p>
</blockquote>
<p>Character encoding issues of N3 are not well-defined; hence use of
these methods may require changes in the future. Use of the
InputStream and OutputStream methods will allow your code to work
with future versions of Jena which do the right thing - whatever
that is. Currently the OutputStream methods use UTF-8 encoding.</p>
<h2 id="introduction-to-advanced-jena-io">Introduction to Advanced Jena I/O</h2>
<p>The RDF/XML input and output is configurable.
However, to configure it, it is necessary to access an <code>RDFReader</code> or
<code>RDFWriter</code> object that remains hidden in the simpler interface
above.</p>
<p>The four vital calls in the <code>Model</code> interface are:</p>
<ul>
<li><a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/RDFReader.html"><code>RDFReader</code></a>
<a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/RDFReaderF.html#getReader()"><code>getReader</code></a><code>()</code>
<br />Return an RDFReader instance for the default serialization language.</li>
<li><a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/RDFReader.html"><code>RDFReader</code></a>
<a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/RDFReaderF.html#getReader(java.lang.String)"><code>getReader</code></a><code>(java.lang.String lang)</code>
<br />Return an RDFReader instance for the specified serialization language.</li>
<li><a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/RDFReader.html"><code>RDFReader</code></a>
<a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/RDFWriterF.html#getWriter()"><code>getWriter</code></a><code>()</code>
<br />Return an RDFWriter instance for the default serialization language.</li>
<li><a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/RDFReader.html"><code>RDFReader</code></a>
<a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/RDFWriterF.html#getWriter(java.lang.String)"><code>getWriter</code></a><code>(java.lang.String lang)</code>
<br />An RDFWriter instance for the specified serialization language.</li>
</ul>
<p>Each of these calls returns an <code>RDFReader</code> or <code>RDFWriter</code> that can be
used to read or write any <code>Model</code> (not just the one which created
it). As well as the necessary
[<code>read</code>](/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/RDFReader.html#read(org.apache.jena.rdf.model.Model, java.io.InputStream, java.lang.String))
and
[<code>write</code>](/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/RDFWriter.html#write(org.apache.jena.rdf.model.Model, java.io.OutputStream, java.lang.String))
methods, these interfaces provide:</p>
<ul>
<li><a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/RDFErrorHandler.html"><code>RDFErrorHandler</code></a>
<a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/RDFReader.html#setErrorHandler(org.apache.jena.rdf.model.RDFErrorHandler)"><code>setErrorHandler</code></a><code>(</code> <a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/RDFErrorHandler.html">RDFErrorHandler</a> <code>errHandler )</code>
<br />Set an error handler for the reader</li>
<li><code>java.lang.Object</code>
[<code>setProperty</code>](/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/RDFReader.html#setProperty(java.lang.String, java.lang.Object))<code>(java.lang.String propName, java.lang.Object propValue)</code>
<br />Set the value of a reader property.</li>
</ul>
<p>Setting properties, or the error handler, on an <code>RDFReader</code> or an
<code>RDFWriter</code> allows the programmer to access non-default behaviour.
Moreover, since the <code>RDFReader</code> and <code>RDFWriter</code> is not bound to a
specific <code>Model</code>, a typical idiom is to create the <code>RDFReader</code> or
<code>RDFWriter</code> on system initialization, to set the appropriate
properties so that it behaves exactly as required in your application,
and then to do all subsequent I/O through it.</p>
<pre><code>Model m = ModelFactory.createDefaultModel();
RDFWriter writer = m.getRDFWriter();
m = null; // m is no longer needed.
writer.setErrorHandler(myErrorHandler);
writer.setProperty(&quot;showXmlDeclaration&quot;,&quot;true&quot;);
writer.setProperty(&quot;tab&quot;,&quot;8&quot;);
writer.setProperty(&quot;relativeURIs&quot;,&quot;same-document,relative&quot;);
Model marray[];
for (int i=0; i&lt;marray.length; i++) {
OutputStream out = new FileOutputStream(&quot;foo&quot; + i + &quot;.rdf&quot;);
writer.write(marray[i],
out,
&quot;http://example.org/&quot;);
out.close();
}
</code></pre>
<p>Note that all of the current implementations are synchronized, so
that a specific <code>RDFReader</code> cannot be reading two different documents
at the same time. In a multi-threaded application this may suggest a
need for a pool of <code>RDFReader</code>s and/or <code>RDFWriter</code>s, or alternatively
to create, initialize, use and discard them as needed.</p>
<p>For N-TRIPLE there are currently no properties supported for
either the <code>RDFReader</code> or the <code>RDFWriter</code>. Hence this idiom above is
not very helpful, and just using the <code>Model.write()</code> methods may
prove easier.</p>
<p>For RDF/XML and RDF/XML-ABBREV, there are many options in both the
<code>RDFReader</code> and the <code>RDFWriter</code>. N3 has options on the <code>RDFWriter</code>. These
options are detailed below. For RDF/XML they are also found in the
JavaDoc for
<code>JenaReader.</code>[<code>setProperty</code>](/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdfxml/xmlinput/JenaReader.html#setProperty(java.lang.String, java.lang.Object))<code>(String, Object)</code>
and
<code>RDFXMLWriterI.</code>[<code>setProperty</code>](/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/xmloutput/RDFXMLWriterI.html#setProperty(java.lang.String, java.lang.Object))<code>(String, Object)</code>.</p>
<h2 id="advanced-rdfxml-input">Advanced RDF/XML Input</h2>
<p>For access to these advanced features, first get an <code>RDFReader</code>
object that is an instance of an ARP parser, by using the
<a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/RDFReaderF.html#getReader()"><code>getReader</code></a><code>()</code>
method on any <code>Model</code>. It is then configured using the
[<code>setProperty</code>](/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdfxml/xmlinput/JenaReader.html#setProperty(java.lang.String, java.lang.Object))<code>(String, Object)</code>
method. This changes the properties for parsing RDF/XML. Many of
the properties change the RDF parser, some change the XML parser.
(The Jena RDF/XML parser, ARP, implements the
<a href="http://www.w3.org/TR/rdf-syntax-grammar/#section-Infoset-Grammar">RDF grammar</a>
over a <a href="http://xml.apache.org/xerces2-j/index.html">Xerces2-J</a> XML
parser). However, changing the features and properties of the XML
parser is not likely to be useful, but was easy to implement.</p>
<p>[<code>setProperty</code>](/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdfxml/xmlinput/JenaReader.html#setProperty(java.lang.String, java.lang.Object))<code>(String, Object)</code>
can be used to set and get:</p>
<ul>
<li>ARP properties
<br /> These allow fine grain control over the extensive error
reporting capabilities of ARP. And are detailed directly below.</li>
<li>SAX2 features
<br />See
<a href="http://xml.apache.org/xerces2-j/features.html">Xerces features</a>.
Value should be given as a String <code>&quot;true&quot;</code> or <code>&quot;false&quot;</code> or a <code>Boolean</code>.</li>
<li>SAX2 properties
<br /> See <a href="http://xml.apache.org/xerces2-j/properties.html">Xerces properties</a>.</li>
<li>Xerces features
<br /> See <a href="http://xml.apache.org/xerces2-j/features.html">Xerces features</a>.
Value should be given as a String <code>&quot;true&quot;</code> or <code>&quot;false&quot;</code> or a <code>Boolean</code>.</li>
<li>Xerces properties
<br /> See <a href="http://xml.apache.org/xerces2-j/properties.html">Xerces properties</a>.</li>
</ul>
<h3 id="arp-properties">ARP properties</h3>
<p>An ARP property is referred to either by its property name, (see
below) or by an absolute URL of the form
<code>http://jena.hpl.hp.com/arp/properties/&lt;PropertyName&gt;</code>. The value
should be a String, an Integer or a Boolean depending on the
property.</p>
<p>ARP property names and string values are case insensitive.</p>
<table>
<thead>
<tr>
<th>Property Name</th>
<th>Description</th>
<th>Value class</th>
<th>Legal Values</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>iri-rules</code></td>
<td>Set the engine for checking and resolving. <code>&quot;strict&quot;</code> sets the IRI engine with rules for valid IRIs, XLink and RDF; it does not permit spaces in IRIs. <code>&quot;iri&quot;</code>sets the IRI engine to IRI (<a href="http://www.ietf.org/rfc/rfc3986.txt">RFC 3986</a>, <a href="http://www.ietf.org/rfc/rfc3987.txt">RFC 3987</a>) <code>.</code> The default is <code>&quot;lax&quot;</code>(for backwards compatibility)<code>,</code> the rules for RDF URI references only, which does permit spaces although the use of spaces is not good practice.</td>
<td>String</td>
<td><code>lax</code><br /><code>strict</code><br /><code>iri</code></td>
</tr>
<tr>
<td><code>error-mode</code></td>
<td><a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdfxml/xmlinput/ARPOptions.html#setDefaultErrorMode()"><code>ARPOptions.setDefaultErrorMode()</code></a> <br /><a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdfxml/xmlinput/ARPOptions.html#setLaxErrorMode()"><code>ARPOptions.setLaxErrorMode()</code></a><br /><a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdfxml/xmlinput/ARPOptions.html#setStrictErrorMode()"><code>ARPOptions.setStrictErrorMode()</code></a><br /><a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdfxml/xmlinput/ARPOptions.html#setStrictErrorMode(int)"><code>ARPOptions.setStrictErrorMode(int)</code></a><br /> This allows a coarse-grained approach to control of error handling. Setting this property is equivalent to setting many of the fine-grained error handling properties.</td>
<td><code>String</code></td>
<td><code>default</code><br /><code>lax</code><br /><code>strict</code><br /><code>strict-ignore</code><br /><code>strict-warning</code><br /><code>strict-error</code><br /><code>strict-fatal</code></td>
</tr>
<tr>
<td><code>embedding</code></td>
<td><a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdfxml/xmlinput/ARPOptions.html#setEmbedding(boolean)"><code>ARPOptions.setEmbedding(boolean)</code></a> <br />This sets ARP to look for RDF embedded within an enclosing XML document.</td>
<td><code>String</code> or <code>Boolean</code></td>
<td><code>true</code><br /><code>false</code></td>
</tr>
<tr>
<td><code>ERR_&lt;XXX&gt;</code> <br /><code>WARN_&lt;XXX&gt;</code><br /><code>IGN_&lt;XXX&gt;</code></td>
<td>See <a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdfxml/xmlinput/ARPErrorNumbers.html"><code>ARPErrorNumbers</code></a> for a complete list of the error conditions detected. Setting one of these properties is equivalent to the method <a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdfxml/xmlinput/ARPOptions.html#setErrorMode(int,%20int)"><code>ARPOptions.setErrorMode(int, int)</code></a>. Thus fine-grained control over the behaviour in response to specific error conditions is possible.</td>
<td><code>String</code> or <code>Integer</code></td>
<td><a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdfxml/xmlinput/ARPErrorNumbers.html#EM_IGNORE"><code>EM_IGNORE</code></a><br /><a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdfxml/xmlinput/ARPErrorNumbers.html#EM_WARNING"><code>EM_WARNING</code></a><br /><a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdfxml/xmlinput/ARPErrorNumbers.html#EM_ERROR"><code>EM_ERROR</code></a><br /><a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdfxml/xmlinput/ARPErrorNumbers.html#EM_FATAL"><code>EM_FATAL</code></a></td>
</tr>
</tbody>
</table>
<p>As an example, if you are working in an environment with legacy RDF
data that uses unqualified RDF attributes such as &ldquo;about&rdquo; instead
of &ldquo;rdf:about&rdquo;, then the following code is appropriate:</p>
<pre><code>Model m = ModelFactory.createDefaultModel();
RDFReader arp = m.getReader();
m = null; // m is no longer needed.
// initialize arp
// Do not warn on use of unqualified RDF attributes.
arp.setProperty(&quot;WARN_UNQUALIFIED_RDF_ATTRIBUTE&quot;,&quot;EM_IGNORE&quot;);
InputStream in = new FileInputStream(fname);
arp.read(m,in,url);
in.close();
</code></pre>
<p>As a second example, suppose you wish to work in strict mode, but
allow <code>&quot;daml:collection&quot;</code>, the following works:</p>
<pre><code>
arp.setProperty(&quot;error-mode&quot;, &quot;strict&quot; );
arp.setProperty(&quot;IGN_DAML_COLLECTION&quot;,&quot;EM_IGNORE&quot;);
</code></pre>
<p>The other way round does not work.</p>
<pre><code>
arp.setProperty(&quot;IGN_DAML_COLLECTION&quot;,&quot;EM_IGNORE&quot;);
arp.setProperty(&quot;error-mode&quot;, &quot;strict&quot; );
</code></pre>
<p>This is because in strict mode
<a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdfxml/xmlinput/ARPErrorNumbers.html#IGN_DAML_COLLECTION"><code>IGN_DAML_COLLECTION</code></a>
is treated as an error, and so the second call to <code>setProperty</code>
overwrites the effect of the first.</p>
<p>The IRI rules and resolver can be set on a per-reader basis:</p>
<pre><code>InputStream in = ... ;
String baseURI = ... ;
Model model = ModelFactory.createDefaultModel();
RDFReader r = model.getReader(&quot;RDF/XML&quot;);
r.setProperty(&quot;iri-rules&quot;, &quot;strict&quot;) ;
r.setProperty(&quot;error-mode&quot;, &quot;strict&quot;) ; // Warning will be errors.
// Alternative to the above &quot;error-mode&quot;: set specific warning to be an error.
//r.setProperty( &quot;WARN_MALFORMED_URI&quot;, ARPErrorNumbers.EM_ERROR) ;
r.read(model, in, baseURI) ;
in.close();
</code></pre>
<p>The global default IRI engine can be set with:</p>
<pre><code>ARPOptions.setIRIFactoryGlobal(IRIFactory.iriImplementation()) ;
</code></pre>
<p>or other IRI rule engine from <code>IRIFactory</code>.</p>
<h3 id="interrupting-arp">Interrupting ARP</h3>
<p>ARP can be interrupted using the <code>Thread.interrupt()</code> method. This
causes an
<a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdfxml/xmlinput/ARPErrorNumbers.html#ERR_INTERRUPTED"><code>ERR_INTERRUPTED</code></a>
error during the parse, which is usually treated as a fatal error.</p>
<p>Here is an illustrative code sample:</p>
<pre><code>ARP a = new ARP();
final Thread arpt = Thread.currentThread();
Thread killt = new Thread(new Runnable() {
public void run() {
try {
Thread.sleep(tim);
} catch (InterruptedException e) {
}
arpt.interrupt();
}
});
killt.start();
try {
in = new FileInputStream(fileName);
a.load(in);
in.close();
fail(&quot;Thread was not interrupted.&quot;);
} catch (SAXParseException e) {
}
</code></pre>
<h2 id="advanced-rdfxml-output">Advanced RDF/XML Output</h2>
<p>The first RDF/XML output question is whether to use the <code>&quot;RDF/XML&quot;</code>
or <code>&quot;RDF/XML-ABBREV&quot;</code> writer. While some of the code is shared, these
two writers are really very different, resulting in different but
equivalent output. <code>RDF/XML-ABBREV</code> is slower, but should produce
more readable XML.</p>
<p>For access to advanced features, first get an RDFWriter object, of
the appropriate language, by using
<a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/RDFWriterF.html#getWriter(java.lang.String)"><code>getWriter</code></a><code>(&quot;RDF/XML&quot;)</code>
or
<a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/RDFWriterF.html#getWriter(java.lang.String)"><code>getWriter</code></a><code>(&quot;RDF/XML-ABBREV&quot;)</code>
on any <code>Model</code>. It is then configured using the
[<code>setProperty</code>](/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdfxml/xmlinput/JenaReader.html#setProperty(java.lang.String, java.lang.Object))<code>(String, Object)</code>
method. This changes the properties for writing RDF/XML.</p>
<h3 id="properties-to-control-rdfxml-output">Properties to Control RDF/XML Output</h3>
<table>
<tr><th>Property Name</th><th>Description</th><th>Value class</th><th>Legal Values</th></tr>
<tr>
<td><tt>xmlbase</tt></td>
<td>The value to be included for an xml:base attribute on the root element in the file.</td>
<td><tt>String</tt></td>
<td>A URI string, or null (default)</td>
</tr>
<tr>
<td><tt>longId</tt></td>
<td>Whether to use long or short id's for anon resources. Short id's are easier to read and are the default, but can run out of memory on very large models.</td>
<td><tt>String</tt> or <tt>Boolean</tt></td>
<td><tt>"true"</tt>, <tt>"false"</tt> (default)</td>
</tr>
<tr>
<td><tt>allowBadURIs</tt></td>
<td>URIs in the graph are, by default, checked prior to serialization.</td>
<td><tt>String</tt> or <tt>Boolean</tt></td>
<td><tt>"true"</tt>, <tt>"false"</tt> (default)</td>
</tr>
<tr>
<td><tt>relativeURIs</tt></td>
<td>What sort of relative URIs should be used. A comma separated list of options:
<ul>
<li><em>same-document</em><br />
same-document references (e.g. &quot;&quot; or &ldquo;#foo&rdquo;)</li>
<li><em>network</em><br />
network paths e.g. <code>&quot;//example.org/foo&quot;</code> omitting the URI scheme</li>
<li><em>absolute</em><br />
absolute paths e.g. <code>&quot;/foo&quot;</code> omitting the scheme and authority</li>
<li><em>relative</em><br />
relative path not beginning in <code>&quot;../&quot;</code></li>
<li><em>parent</em><br />
relative path beginning in <code>&quot;../&quot;</code></li>
<li><em>grandparent</em><br />
relative path beginning in <code>&quot;../../&quot;</code></li>
</ul>
<p>The default value is &ldquo;same-document, absolute, relative, parent&rdquo;.
To switch off relative URIs use the value &ldquo;&rdquo;. Relative URIs of any
of these types are output where possible if and only if the option
has been specified.</td></p>
<td>String</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><tt>showXmlDeclaration</tt></td>
<td>
If true, an XML Declaration is included in the output, if false no XML declaration is included.
The default behaviour only gives an XML Declaration when asked to write to an `OutputStreamWriter`
that uses some encoding other than UTF-8 or UTF-16. In this case the encoding is shown in the
XML declaration. To ensure that the encoding attribute is shown in the XML declaration either:
<ul>
<li>Set this option to true and use the
<code>write(Model,Writer,String)</code> variant with an appropriate <code>OutputStreamWriter</code>.</li>
<li>Or set this option to false, and write the declaration to an <code>OutputStream</code> before calling
<code>write(Model,OutputStream,String)</code>.</li>
</ul>
</td>
<td><tt>true</tt>, <tt>"true"</tt>, <tt>false</tt>, <tt>"false"</tt> or <tt>"default"</tt></td>
<td>can be true, false or "default" (null)</td>
</tr>
<tr>
<td><tt>showDoctypeDeclaration</tt></td>
<td>
If true, an XML Doctype declaration is included in the output. This
declaration includes a `!ENTITY` declaration for each prefix mapping
in the model, and any attribute value that starts with the URI of
that mapping is written as starting with the corresponding entity
invocation.
</td>
<td><tt>String</tt> or <tt>Boolean</tt></td>
<td><tt>true</tt>, <tt>false</tt>, <tt>"true"</tt>, <tt>"false"</tt></td>
</tr>
<tr>
<td><tt>tab</tt></td>
<td>The number of spaces with which to indent XML child elements.</td>
<td><tt>String</tt> or <tt>Integer</tt></td>
<td>positive integer "2" is the default</td>
</tr>
<tr>
<td><tt>attributeQuoteChar</tt></td>
<td>How to write XML attributes.</td>
<td><tt>String</tt></td>
<td><tt>"\""</tt> or <tt>"'"</tt></td>
</tr>
<tr>
<td><tt>blockRules</tt></td>
<td>
A list of `Resource` or a `String` being a comma separated list of
fragment IDs from [http://www.w3.org/TR/rdf-syntax-grammar](http://www.w3.org/TR/rdf-syntax-grammar)
indicating grammar rules that will not be used. Rules that can be blocked are:
<ul>
<li><a href="http://www.w3.org/TR/rdf-syntax-grammar#section-Reification">section-Reification</a>
(<a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/vocabulary/RDFSyntax.html#sectionReification"><code>RDFSyntax.sectionReification</code></a>)</li>
<li><a href="http://www.w3.org/TR/rdf-syntax-grammar#section-List-Expand">section-List-Expand</a>
(<a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/vocabulary/RDFSyntax.html#sectionListExpand"><code>RDFSyntax.sectionListExpand</code></a>)</li>
<li><a href="http://www.w3.org/TR/rdf-syntax-grammar#parseTypeLiteralPropertyElt">parseTypeLiteralPropertyElt</a>
(<a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/vocabulary/RDFSyntax.html#parseTypeLiteralPropertyElt"><code>RDFSyntax.parseTypeLiteralPropertyElt</code></a>)</li>
<li><a href="http://www.w3.org/TR/rdf-syntax-grammar#parseTypeResourcePropertyElt">parseTypeResourcePropertyElt</a>
(<a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/vocabulary/RDFSyntax.html#parseTypeLiteralPropertyElt"><code>RDFSyntax.parseTypeLiteralPropertyElt</code></a>)</li>
<li><a href="http://www.w3.org/TR/rdf-syntax-grammar#parseTypeCollectionPropertyElt">parseTypeCollectionPropertyElt</a>
(<a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/vocabulary/RDFSyntax.html#parseTypeCollectionPropertyElt"><code>RDFSyntax.parseTypeCollectionPropertyElt</code></a>)</li>
<li><a href="http://www.w3.org/TR/rdf-syntax-grammar#idAttr">idAttr</a>
(<a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/vocabulary/RDFSyntax.html#idAttr"><code>RDFSyntax.idAttr</code></a>)</li>
<li><a href="http://www.w3.org/TR/rdf-syntax-grammar#propertyAttr">propertyAttr</a>
(<a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/vocabulary/RDFSyntax.html#propertyAttr"><code>RDFSyntax.propertyAttr</code></a>)</li>
</ul>
<p>In addition <code>&quot;daml:collection&quot;</code>
(<a href="/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/vocabulary/DAML_OIL.html#collection"><code>DAML_OIL.collection</code></a>)
can be blocked. Blocking
<a href="http://www.w3.org/TR/rdf-syntax-grammar#idAttr">idAttr</a> also
blocks
<a href="http://www.w3.org/TR/rdf-syntax-grammar#section-Reification">section-Reification</a>.
By default, rule
<a href="http://www.w3.org/TR/rdf-syntax-grammar#propertyAttr">propertyAttr</a>
is blocked. For the basic writer (RDF/XML) only
<a href="http://www.w3.org/TR/rdf-syntax-grammar#parseTypeLiteralPropertyElt">parseTypeLiteralPropertyElt</a>
has any effect, since none of the other rules are implemented by
that writer.</p>
</td>
<td><tt>Resource[]</tt> or <tt>String</tt></td>
<td></td>
</tr>
<tr>
<td><tt>prettyTypes</tt></td>
<td>
Only for the RDF/XML-ABBREV writer. This is a list of the types of
the principal objects in the model. The writer will tend to create
RDF/XML with resources of these types at the top level.
</td>
<td>
<tt>Resource[]</tt>
</td>
<td></td>
</tr>
</table>
<p>As an example,</p>
<pre><code>RDFWriter w = m.getWriter(&quot;RDF/XML-ABBREV&quot;);
w.setProperty(&quot;attributeQuoteChar&quot;,&quot;'&quot;);
w.setProperty(&quot;showXMLDeclaration&quot;,&quot;true&quot;);
w.setProperty(&quot;tab&quot;,&quot;1&quot;);
w.setProperty(&quot;blockRules&quot;,
&quot;daml:collection,parseTypeLiteralPropertyElt,&quot;
+&quot;parseTypeResourcePropertyElt,parseTypeCollectionPropertyElt&quot;);
</code></pre>
<p>creates a writer that does not use rdf:parseType (preferring
rdf:datatype for rdf:XMLLiteral), indents only a little, and
produces the XMLDeclaration. Attributes are used, and are quoted
with <code>&quot;'&quot;</code>.</p>
<p>Note that property attributes are not used at all, by default.
However, the RDF/XML-ABBREV writer includes a rule to produce
property attributes when the value does not contain any spaces.
This rule is normally switched off. This rule can be turned on
selectively by using the blockRules property as detailed above.</p>
<h2 id="conformance">Conformance</h2>
<p>The RDF/XML I/O endeavours to conform with the
<a href="http://www.w3.org/TR/rdf-syntax-grammar/">RDF Syntax Recommendation</a>.</p>
<p>The parser must be set to strict mode. (Note that, the conformant
behaviour for <code>rdf:parseType=&quot;daml:collection&quot;</code> is to silently turn
<code>&quot;daml:collection&quot;</code> into <code>&quot;Literal&quot;</code>).</p>
<p>The RDF/XML writer is conformant, but does not exercise much of the
grammar.</p>
<p>The RDF/XML-ABBREV writer exercises all of the grammar and is
conformant except that it uses the <code>daml:collection</code> construct for
DAML ontologies. This non-conformant behaviour can be switched off
using the <code>blockRules</code> property.</p>
<h2 id="faster-rdfxml-io">Faster RDF/XML I/O</h2>
<p>To optimise the speed of writing RDF/XML it is suggested that all
URI processing is turned off. Also do not use RDF/XML-ABBREV. It is
unclear whether the longId attribute is faster or slower; the short
IDs have to be generated on the fly and a table maintained during
writing. The longer IDs are long, and hence take longer to write.
The following creates a faster writer:</p>
<pre><code>Model m;
RDFWriter fasterWriter = m.getWriter(&quot;RDF/XML&quot;);
fasterWriter.setProperty(&quot;allowBadURIs&quot;,&quot;true&quot;);
fasterWriter.setProperty(&quot;relativeURIs&quot;,&quot;&quot;);
fasterWriter.setProperty(&quot;tab&quot;,&quot;0&quot;);
</code></pre>
<p>When reading RDF/XML the check for reuse of rdf:ID has a memory
overhead, which can be significant for very large files. In this
case, this check can be suppressed by telling ARP to ignore this
error.</p>
<pre><code>Model m;
RDFReader bigFileReader = m.getReader(&quot;RDF/XML&quot;);
bigFileReader.setProperty(&quot;WARN_REDEFINITION_OF_ID&quot;,&quot;EM_IGNORE&quot;);
</code></pre>
</article>
<aside class="text-muted align-self-start mb-3 mb-xl-5 p-0 d-none d-xl-flex flex-column sticky-top">
<h2 class="h6 sticky-top m-0 p-2 bg-body-tertiary">On this page</h2>
<nav id="TableOfContents">
<ul>
<li><a href="#quick-introduction">Quick Introduction</a></li>
<li><a href="#rdfxml-rdfxml-abbrev">RDF/XML, RDF/XML-ABBREV</a></li>
<li><a href="#character-encoding-issues">Character Encoding Issues</a>
<ul>
<li><a href="#encodings-supported-in-jena-22-and-later">Encodings Supported in Jena 2.2 and later</a></li>
</ul>
</li>
<li><a href="#when-to-use-reader-and-writer">When to Use Reader and Writer?</a></li>
<li><a href="#introduction-to-advanced-jena-io">Introduction to Advanced Jena I/O</a></li>
<li><a href="#advanced-rdfxml-input">Advanced RDF/XML Input</a>
<ul>
<li><a href="#arp-properties">ARP properties</a></li>
<li><a href="#interrupting-arp">Interrupting ARP</a></li>
</ul>
</li>
<li><a href="#advanced-rdfxml-output">Advanced RDF/XML Output</a>
<ul>
<li><a href="#properties-to-control-rdfxml-output">Properties to Control RDF/XML Output</a></li>
</ul>
</li>
<li><a href="#conformance">Conformance</a></li>
<li><a href="#faster-rdfxml-io">Faster RDF/XML I/O</a></li>
</ul>
</nav>
</aside>
</main>
</div>
</div>
</div>
<footer class="bd-footer py-4 py-md-5 mt-4 mt-lg-5 bg-body-tertiary">
<div class="container" style="font-size:80%" >
<p>
Copyright &copy; 2011&ndash;2024 The Apache Software Foundation, Licensed under the
<a href="https://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.
</p>
<p>
Apache Jena, Jena, the Apache Jena project logo, Apache and the Apache feather logos are trademarks of
The Apache Software Foundation.
<br/>
<a href="https://privacy.apache.org/policies/privacy-policy-public.html"
>Apache Software Foundation Privacy Policy</a>.
</p>
</div>
</footer>
<script src="/js/popper.min.js.js" type="text/javascript"></script>
<script src="/js/bootstrap.min.js" type="text/javascript"></script>
<script src="/js/improve.js" type="text/javascript"></script>
<script type="text/javascript">
(function() {
'use strict'
const links = document.querySelectorAll(`a[href="${window.location.pathname}"]`)
if (links !== undefined && links !== null) {
for (const link of links) {
link.classList.add('active')
let parentElement = link.parentElement
let count = 0
const levelsLimit = 4
while (['UL', 'LI'].includes(parentElement.tagName) && count <= levelsLimit) {
if (parentElement.tagName === 'LI') {
parentElement.querySelector('a:first-child').classList.add('active')
}
parentElement = parentElement.parentElement
count++
}
}
}
})()
</script>
</body>
</html>