Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
s-xml
s-xml
Commits
92602915
Commit
92602915
authored
Jun 11, 2004
by
Sven Van Caekenberghe
Browse files
a new example to help understand the SAX api (hook functions)
parent
9c02d1ac
Changes
1
Hide whitespace changes
Inline
Side-by-side
test/tracer.lisp
0 → 100644
View file @
92602915
;;;; -*- mode: lisp -*-
;;;;
;;;; $Id: counter.lisp,v 1.1.1.1 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
;;;; (http://opensource.franz.com/preamble.html), 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
)
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment