Commit 92602915 authored by Sven Van Caekenberghe's avatar Sven Van Caekenberghe
Browse files

a new example to help understand the SAX api (hook functions)

parent 9c02d1ac
;;;; -*- mode: lisp -*-
;;;; $Id: counter.lisp,v 2004/06/07 18:49:59 scaekenberghe Exp $
;;;; A simple SAX tracer example that can be used to understand how the hooks are called
;;;; Copyright (C) 2004 Sven Van Caekenberghe, Beta Nine BVBA.
;;;; You are granted the rights to distribute and use this software
;;;; as governed by the terms of the Lisp Lesser General Public License
;;;; (, also known as the LLGPL.
(in-package :s-xml)
(defun trace-xml-log (level msg &rest args)
(indent *standard-output* level)
(apply #'format *standard-output* msg args)
(terpri *standard-output*))
(defun trace-xml-new-element-hook (name attributes seed)
(trace-xml-log (car seed)
"(new-element :name ~s :attributes ~:[()~;~:*s~] :seed ~s)"
name attributes seed)
(cons (1+ (car seed)) (1+ (cdr seed))))
(defun trace-xml-finish-element-hook (name attributes parent-seed seed)
(trace-xml-log (car parent-seed)
"(finish-element :name ~s :attributes ~:[()~;~:*s~] :parent-seed ~s :seed ~s)"
name attributes parent-seed seed)
(cons (1- (car seed)) (1+ (cdr seed))))
(defun trace-xml-text-hook (string seed)
(trace-xml-log (car seed)
"(text :string ~s :seed ~s)"
string seed)
(defun trace-xml (in)
"Parse and trace a toplevel XML element from stream in"
(start-parse-xml in
(make-instance 'xml-parser-state
:seed (cons 0 0)
:new-element-hook #'trace-xml-new-element-hook
:finish-element-hook #'trace-xml-finish-element-hook
:text-hook #'trace-xml-text-hook)))
(defun trace-xml-file (pathname)
"Parse and trace XMl from the file at pathname"
(with-open-file (in pathname)
(trace-xml in)))
;;;; eof
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment