data.gov now live with RDFa

Hello All:

Just to give you a heads up the data.gov home page is now live with RDFa 
tags.

http://www.data.gov/

The page has two triples. One about the page, one about the program. We 
used this very simplistic approach to overcome any operational barriers 
and develop experience in publishing RDFa tags.

See below for source code that parses the triples. I used the INRIA 
GRDDL transform.

Have fun and I'll watch this list for feedback and such.

-- 
Rick

cell: 703-201-9129
web:  http://www.rickmurphy.org
blog: http://phaneron.rickmurphy.org

 > more RDFaConsumer.java
/**
  * @(#)RDFaConsumer.java
  * @author rick@rickmurphy.org
  */

package gov.data;

/**
  */

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;

import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

import java.text.ParseException;

import java.io.UnsupportedEncodingException;
import java.io.IOException;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Element;

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;


import java.net.URL;

public class RDFaConsumer{

     private static String namespace;

     /**
      */
     public RDFaConsumer(String uri){

	try {
	
	    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
             DocumentBuilder builder = factory.newDocumentBuilder();
  	    Document input = builder.parse(new URL(uri).toString());
	    input.normalize();

	    DOMSource source = new DOMSource(input);
	    StreamResult result = new StreamResult(System.out);
	    StreamSource stylesheet = new StreamSource(new 
URL("http://ns.inria.fr/grddl/
rdfa/2008/09/03/RDFa2RDFXML.xsl").toString());

	    // Use a Transformer for output
	    TransformerFactory tFactory = TransformerFactory.newInstance();
	    Transformer transformer = tFactory.newTransformer(stylesheet);
	    transformer.transform(source, result);

	    // transform the dom into RDF/XML
	    traverse(input);

         } catch (SAXParseException spe) {
	    System.out.println("sax parse ex: " + spe);
         } catch (SAXException sxe) {
	    System.out.println("sax ex: " + sxe);
         } catch (ParserConfigurationException pce) {
	    System.out.println("parser config ex: " + pce);
         }catch (UnsupportedEncodingException ude) {
	    System.out.println("unsupported encoding ex: " + ude);
         } catch (IOException ioe) {
	    System.out.println("io ex: " + ioe);
         } catch (TransformerConfigurationException tc) {
	    System.out.println("transformer config ex: " + tc);
         } catch (TransformerException te) {
	    System.out.println("trasnformer ex: " + te);
         }

     }//RDFaConsumer

     /**
      */
     public static void main(String[] args){

	new RDFaConsumer(args[0]);

     }//main

     /**
      */
     public void traverse(Node node){

         // is there anything to do?
         if (node == null) {
             return;
         }
	
         int type = node.getNodeType();
         switch (type) {
	case Node.DOCUMENT_NODE: {;
                 Document document = (Document)node;
                 traverse(document.getDocumentElement());
                 break;
	}
	
	case Node.ELEMENT_NODE: {
	
	    if(node.getNodeName().equals("")){
		
		NodeList childNodes = node.getChildNodes();
		
		break;
		
	    }
	}
	
	case Node.ENTITY_REFERENCE_NODE: {
	    Node child = node.getFirstChild();
	    while (child != null) {
		traverse(child);
		child = child.getNextSibling();
	    }
	    break;
	}
	
	case Node.CDATA_SECTION_NODE: {
	
	    // no work here
	    break;
	}
	
	}
	
     }//traverse

     /**
      */
     public void getRDFaHTML(){}//getRDFaHTML

}//RDFaConsumer

Received on Wednesday, 19 August 2009 10:54:25 UTC