1#!/usr/bin/env tclsh
2# $Id: rdfExample.xotcl,v 1.2 2006/02/18 22:17:33 neumann Exp $
3#
4# small Example for usage of xoXML
5#
6package require XOTcl; namespace import -force xotcl::*
7package require xotcl::package
8package require xotcl::trace
9package require xotcl::rdf::parser
10package require xotcl::rdf::recreatorVisitor
11package require xotcl::xml::printVisitor
12
13#
14# instantiate parser and parser an example text into a node tree
15#
16RDFParser x
17x parse {
18  <rdf:RDF
19    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
20    xmlns:dc="http://purl.org/metadata/dublin_core#"> 
21    <rdf:Description about="http://www.foo.com/cool.html"> 
22      <dc:Creator>
23        <rdf:Seq ID="CreatorsAlphabeticalBySurname">
24          <rdf:li>Mary Andrew</rdf:li>
25          <rdf:li>Jacky Crystal</rdf:li>
26        </rdf:Seq>
27      </dc:Creator>
28
29      <dc:Identifier>
30        <rdf:Bag ID="MirroredSites"> 
31          <rdf:li rdf:resource="http://www.foo.com.au/cool.html"/>
32          <rdf:li rdf:resource="http://www.foo.com.it/cool.html"/>
33        </rdf:Bag>
34      </dc:Identifier>
35
36      <dc:Title>
37        <rdf:Alt>
38          <rdf:li xml:lang="en">The Coolest Web Page</rdf:li>
39          <rdf:li xml:lang="it">Il Pagio di Web Fuba</rdf:li>
40        </rdf:Alt>
41      </dc:Title>
42     
43      <dc:xxx>
44        some text
45      </dc:xxx>
46
47    </rdf:Description> 
48  </rdf:RDF>
49}
50
51proc run {} {
52  #
53  # print the node treee to the std output
54  #
55  puts ************************************************************************
56  puts "Node Tree:"
57  puts ************************************************************************
58  PrintVisitor pv
59  foreach tn [x info children topNode*] {
60    pv interpretNodeTree $tn
61  }
62  
63  #
64  # recreate xml text and print it to the std output
65  #
66  puts \n
67  puts ************************************************************************
68  puts "Recreated RDF Text:"
69  puts ************************************************************************
70  RDFRecreatorVisitor rv
71  foreach tn [x info children topNode*] {
72    set result [rv interpretNodeTree  $tn]
73    puts $result
74  }
75}
76run
77