rdf_xml 0.4.0 copy "rdf_xml: ^0.4.0" to clipboard
rdf_xml: ^0.4.0 copied to clipboard

A rdf/xml decoder and encoder for https://pub.dev/packages/rdf_core .

example/main.dart

// Basic usage of the rdf_xml package
// Shows how to integrate with RdfCore and
// then decode and encode RDF/XML data

import 'package:rdf_core/rdf_core.dart';
import 'package:rdf_xml/rdf_xml.dart';

void main() {
  // Example RDF/XML content
  final xmlContent = '''
    <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
             xmlns:dc="http://purl.org/dc/elements/1.1/"
             xmlns:foaf="http://xmlns.com/foaf/0.1/">
      <rdf:Description rdf:about="http://example.org/resource">
        <dc:title>Example Resource</dc:title>
        <dc:creator>Example Author</dc:creator>
        <foaf:maker>
          <foaf:Person>
            <foaf:name>John Doe</foaf:name>
            <foaf:mbox rdf:resource="mailto:john@example.org"/>
          </foaf:Person>
        </foaf:maker>
      </rdf:Description>
    </rdf:RDF>
  ''';

  // OPTIONAL: just use the global rdfxml instance directly, without RdfCore integration. For example:
  // rdfxml.decode(xmlContent);
  // rdfxml.encode(rdfGraph);
  //
  // Below is the RdfCore integration example, which allows for more advanced usage.
  //
  print('--- DECODING EXAMPLE ---\n');

  // Register the codec with the registry
  final rdfCore = RdfCore.withStandardCodecs(additionalCodecs: [RdfXmlCodec()]);

  final rdfGraph = rdfCore.decode(xmlContent);

  // Print the parsed triples
  print('Parsed ${rdfGraph.size} triples:');
  for (final triple in rdfGraph.triples) {
    print('- $triple');
  }

  print('\n--- ENCODING EXAMPLE ---\n');

  // Serialize with custom prefixes
  final rdfXml = rdfCore.encode(rdfGraph, contentType: "application/rdf+xml");

  print('Serialized RDF/XML:');
  print(rdfXml);
}
3
likes
160
points
111
downloads

Publisher

unverified uploader

Weekly Downloads

A rdf/xml decoder and encoder for https://pub.dev/packages/rdf_core .

Homepage
Repository (GitHub)
View/report issues
Contributing

Topics

#rdf #linked-data #semantic-web #xml

Documentation

Documentation
API reference

License

MIT (license)

Dependencies

logging, rdf_core, xml

More

Packages that depend on rdf_xml