あなたは適切なRDFWriterを取得し、あなたの選ばれたxmlbase
にそのxmlbase
プロパティを設定することにより、RDF/XMLシリアル化で使用されるを変更することができます。次のコードは、文字列からモデルを読み込みます(この質問の重要な部分は、frmという形式ではなく、モデルを記述する方法です)、RDF/XMLで2回、毎回異なるを使用して書き込みます。出力され
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.RDFWriter;
public class ChangeBase {
public static void main(String[] args) throws IOException {
final String NS = "http://example.org/";
final String text = "" +
"@prefix ex: <"+NS+">.\n" +
"ex:foo a ex:Foo .\n" +
"ex:foo ex:frob ex:bar.\n";
final Model model = ModelFactory.createDefaultModel();
try (final InputStream in = new ByteArrayInputStream(text.getBytes())) {
model.read(in, null, "TTL");
}
// get a writer for RDF/XML-ABBREV, set its xmlbase to the NS, and write the model
RDFWriter writer = model.getWriter("RDF/XML-ABBREV");
writer.setProperty("xmlbase", NS);
writer.write(model, System.out, null);
// change the base to example.com (.com, not .org) and write again
writer.setProperty("xmlbase", "http://example.com");
writer.write(model, System.out, null);
}
}
(最初のケースでは、塩基はhtttp://example.org/
であり、第二に、それは(差は.ORG対.COMである)http://example.com
だということに気づく:
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:ex="http://example.org/"
xml:base="http://example.org/">
<ex:Foo rdf:about="foo">
<ex:frob rdf:resource="bar"/>
</ex:Foo>
</rdf:RDF>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:ex="http://example.org/"
xml:base="http://example.com">
<ex:Foo rdf:about="http://example.org/foo">
<ex:frob rdf:resource="http://example.org/bar"/>
</ex:Foo>
</rdf:RDF>
これはあなたが投稿した他の回答よりも短く、これよりも簡単です。モデルを読み終えたら、ライターの 'xmlbase'プロパティを設定し、ライターを使ってモデルを書きます。私はこれを示す追加[回答](http://stackoverflow.com/a/18987916/1281433)。 –