Using ARP Without Jena

ARP can be used both as a Jena subsystem, or as a standalone RDF/XML parser. This document gives a quick guide to using ARP standalone.

Contents

1. Overview

To load an RDF file:

  1. Create an ARP instance.
  2. Set parse options, particularly error detection control, using getOptions or setOptionsWith.
  3. Set its handlers, by calling the getHandlers or setHandlersWith methods, and then.
  4. Call a load method

Xerces is used for parsing the XML. The SAXEvents generated by Xerces are then analysed as RDF by ARP. It is possible to use a different source of SAX events.

Errors may occur in either the XML or the RDF part.

2. Sample Code

    ARP arp = new ARP();
        
 // initialisation - uses ARPConfig interface only.
 
    arp.getOptions().setLaxErrorMode();
        
    arp.getHandlers().setErrorHandler(new ErrorHandler(){
    	public void fatalError(SAXParseException e){
               // TODO code
    	}
		public void error(SAXParseException e){
				// TODO code
		}
		public void warning(SAXParseException e){
				// TODO code
		}
    });
    arp.getHandlers().setStatementHandler(new StatementHandler(){
    public void statement(AResource a, AResource b, ALiteral l){
        	// TODO code
    }
	public void statement(AResource a, AResource b, AResource l){
	        // TODO code
    }
    });
 
 // parsing.
 
    try {
    // Loading fixed input ...
        arp.load(new StringReader(
        "<rdf:RDF  xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>\n"
        +"<rdf:Description><rdf:value rdf:parseType='Literal'>"
        +"<b>hello</b></rdf:value>\n"
        +"</rdf:Description></rdf:RDF>"
        ));
        
    }
    catch (IOException ioe){
           // something unexpected went wrong	
    }
    catch (SAXParseException s){
        	// This error will have been reported
    }
    catch (SAXException ss) {
            // This error will not have been reported.
    }

3. ARP Event Handling

ARP reports events concerning:

User code is needed to respond to any of these events of interest. This is written by implementing any of the relevant interfaces: StatementHandler, org.xml.sax.ErrorHandler, NamespaceHandler, and ExtendedHandler.

or setHandlersWith methods, and then.