Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "XDI4j Tutorial 2"
m (logo, category, left menu) |
|||
Line 1: | Line 1: | ||
+ | {{#eclipseproject:technology.higgins}} | ||
+ | [[Image:Higgins_logo_76Wx100H.jpg|right]] | ||
== Example == | == Example == | ||
Line 47: | Line 49: | ||
} | } | ||
</pre> | </pre> | ||
+ | |||
+ | [[Category:Higgins XDI4j]] |
Revision as of 15:16, 18 March 2008
{{#eclipseproject:technology.higgins}}
Example
This example app shows how to output a graph in different serialization formats.
package org.eclipse.higgins.xdi4j.tutorial; import org.eclipse.higgins.xdi4j.Graph; import org.eclipse.higgins.xdi4j.GraphFactory; import org.eclipse.higgins.xdi4j.impl.memory.MemoryGraphFactory; import org.eclipse.higgins.xdi4j.io.XDIWriter; import org.eclipse.higgins.xdi4j.io.XDIWriterRegistry; import org.eclipse.higgins.xdi4j.xri3.impl.XRI3Segment; /** * This example app shows how to output * an graph in different serialization formats. * * @author msabadello at parityinc dot not * */ public class Tutorial2 { public static void main(String[] args) throws Exception { GraphFactory factory = MemoryGraphFactory.getInstance(); Graph graph = factory.openGraph(); // let's create a simple graph graph.createStatement(new XRI3Segment("=markus"), new XRI3Segment("+name"), "Markus"); graph.createStatement(new XRI3Segment("=markus"), new XRI3Segment("+friend"), new XRI3Segment("=giovanni")); graph.createStatement(new XRI3Segment("=giovanni"), new XRI3Segment("+friend"), new XRI3Segment("=drummond")); // output the graph in X3 and XDI/XML XDIWriter writer; writer = XDIWriterRegistry.forFormat("X3"); writer.write(graph, System.out, null); writer = XDIWriterRegistry.forFormat("XDI/XML"); writer.write(graph, System.out, null); graph.close(); } }