blob: 584964f4227293efc3dfe347138556e393397e4a [file] [log] [blame]
<!--
/***************************************************************************************************************************
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
***************************************************************************************************************************/
-->
Typed Literals
<p>
XML-Schema data-types can be added to non-<code>String</code> literals through the
{@link oaj.jena.RdfSerializer#RDF_addLiteralTypes} setting.
</p>
<p>
To enable, set the <jsf>RDF_addLiteralTypes</jsf> property to <jk>true</jk> on the serializer:
</p>
<p class='bpcode w800'>
<jc>// Create a new serializer (revert back to namespace autodetection).</jc>
RdfSerializer s = RdfSerializer.<jsm>create</jsm>()
.xmlabbrev()
.set(RdfProperties.<jsf>RDF_rdfxml_tab</jsf>, 3),
.addLiteralTypes(<jk>true</jk>)
.build();
</p>
<p>
Now when we rerun the sample code, we'll see the added <code>root</code> attribute on the root resource.
</p>
<p class='bpcode w800'>
<xt>&lt;rdf:RDF</xt>
<xa>xmlns:rdf</xa>=<xs>"http://www.w3.org/1999/02/22-rdf-syntax-ns#"</xs>
<xa>xmlns:j</xa>=<xs>"http://www.apache.org/juneau/"</xs>
<xa>xmlns:jp</xa>=<xs>"http://www.apache.org/juneaubp/"</xs>
<xa>xmlns:per</xa>=<xs>"http://www.apache.org/person/"</xs>
<xa>xmlns:mail</xa>=<xs>"http://www.apache.org/mail/"</xs>
<xa>xmlns:addr</xa>=<xs>"http://www.apache.org/address/"</xs><xt>&gt;</xt>
<xt>&lt;rdf:Description <xa>rdf:about</xa>=<xs>"http://sample/addressBook/person/1"</xs>&gt;</xt>
<xt>&lt;per:addressBookUri</xt> <xa>rdf:resource</xa>=<xs>"http://sample/addressBook"</xs><xt>/&gt;</xt>
<xt>&lt;per:id</xt> <b><xa>rdf:datatype</xa>=<xs>"http://www.w3.org/2001/XMLSchema#int"</xs></b><xt>&gt;</xt>1<xt>&lt;/per:id&gt;</xt>
<xt>&lt;per:name&gt;</xt>John Smith<xt>&lt;/per:name&gt;</xt>
<xt>&lt;per:addresses&gt;</xt>
<xt>&lt;rdf:Seq&gt;</xt>
<xt>&lt;rdf:li&gt;</xt>
<xt>&lt;rdf:Description <xa>rdf:about</xa>=<xs>"http://sample/addressBook/address/1"</xs>&gt;</xt>
<xt>&lt;addr:personUri <xa>rdf:resource</xa>=<xs>"http://sample/addressBook/person/1"</xs>/&gt;</xt>
<xt>&lt;addr:id</xt> <b><xa>rdf:datatype</xa>=<xs>"http://www.w3.org/2001/XMLSchema#int"</xs></b>&gt;</xt>1<xt>&lt;/addr:id&gt;</xt>
<xt>&lt;mail:street&gt;</xt>100 Main Street<xt>&lt;/mail:street&gt;</xt>
<xt>&lt;mail:city&gt;</xt>Anywhereville<xt>&lt;/mail:city&gt;</xt>
<xt>&lt;mail:state&gt;</xt>NY<xt>&lt;/mail:state&gt;</xt>
<xt>&lt;mail:zip</xt> <b><xa>rdf:datatype</xa>=<xs>"http://www.w3.org/2001/XMLSchema#int"</xs></b>&gt;</xt>12345<xt>&lt;/mail:zip&gt;</xt>
<xt>&lt;addr:isCurrent</xt> <b><xa>rdf:datatype</xa>=<xs>"http://www.w3.org/2001/XMLSchema#boolean"</xs></b>&gt;</xt>true<xt>&lt;/addr:isCurrent&gt;</xt>
<xt>&lt;/rdf:Description&gt;</xt>
<xt>&lt;/rdf:li&gt;</xt>
<xt>&lt;/rdf:Seq&gt;</xt>
<xt>&lt;/per:addresses&gt;</xt>
<xt>&lt;/rdf:Description&gt;</xt>
<xt>&lt;/rdf:RDF&gt;</xt>
</p>