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
d81401ac
Commit
d81401ac
authored
Jun 11, 2004
by
Sven Van Caekenberghe
Browse files
further cleanup of examples and hook documentation
parent
d192706b
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/xml.lisp
View file @
d81401ac
;;;; -*- mode: lisp -*-
;;;;
;;;; $Id: xml.lisp,v 1.
1.1.1
2004/06/
07 18:49:58
scaekenberghe Exp $
;;;; $Id: xml.lisp,v 1.
2
2004/06/
11 08:22:47
scaekenberghe Exp $
;;;;
;;;; This is a Common Lisp implementation of a very basic XML parser.
;;;; The parser is non-validating and not at all complete (no CDATA).
...
...
@@ -151,9 +151,10 @@
:accessor
get-mini-buffer
:initform
(
make-extendable-string
))
(
new-element-hook
:documentation
"Called when new element starts"
;; Handle a new xml element with name and attributes,
;; receiving seed from parent if any or top level
;; return seed to be used for children/contents"
;; Handle the start of a new xml element with name and attributes,
;; receiving seed from previous element (sibling or parent)
;; return seed to be used for first child (content)
;; or directly to finish-element-hook
:accessor
get-new-element-hook
:initarg
:new-element-hook
:initform
#'
(
lambda
(
name
attributes
seed
)
...
...
@@ -161,17 +162,20 @@
seed
))
(
finish-element-hook
:documentation
"Called when element ends"
;; Handle the end of an xml element with name and attributes,
;; receiving the seed that was passed by our parent,
;; receiving seed from last child/contents
;; return final seed for this element
;; receiving parent-seed, the seed passed to us when this element started,
;; i.e. passed to our corresponding new-element-hook
;; and receiving seed from last child (content)
;; or directly from new-element-hook
;; return final seed for this element to next element (sibling or parent)
:accessor
get-finish-element-hook
:initarg
:finish-element-hook
:initform
#'
(
lambda
(
name
attributes
parent-seed
seed
)
(
declare
(
ignore
name
attributes
parent-seed
))
seed
))
(
text-hook
:documentation
"Called when text is found"
;; Handle text in string, found as child/contents,
;; receiving seed from parent element, return final seed for this element
;; Handle text in string, found as contents,
;; receiving seed from previous element (sibling or parent),
;; return final seed for this element to next element (sibling or parent)
:accessor
get-text-hook
:initarg
:text-hook
:initform
#'
(
lambda
(
string
seed
)
...
...
test/counter.lisp
View file @
d81401ac
;;;; -*- mode: lisp -*-
;;;;
;;;; $Id: counter.lisp,v 1.1 2004/0
5/27 13:51:49 sven
Exp $
;;;; $Id: counter.lisp,v 1.1
.1.1
2004/0
6/07 18:49:59 scaekenberghe
Exp $
;;;;
;;;; A simple SAX counter example that can be used as a performance test
;;;; A simple
S
SAX counter example that can be used as a performance test
;;;;
;;;; Copyright (C) 2004 Sven Van Caekenberghe, Beta Nine BVBA.
;;;;
...
...
@@ -41,7 +41,7 @@
(
let
((
result
(
count-xml
in
)))
(
with-slots
(
elements
attributes
characters
)
result
(
format
t
"~a co
u
ntains ~d XML elements, ~d attributes and ~d characters.~%"
"~a contains ~d XML elements, ~d attributes and ~d characters.~%"
pathname
elements
attributes
characters
)))))
;;;; eof
test/remove-markup.lisp
0 → 100644
View file @
d81401ac
;;;; -*- mode: lisp -*-
;;;;
;;;; $Id: lxml-dom.lisp,v 1.1.1.1 2004/06/07 18:49:56 scaekenberghe Exp $
;;;;
;;;; Remove markup from an XML document using the SSAX interface
;;;;
;;;; 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
remove-xml-markup
(
in
)
(
let*
((
state
(
make-instance
'xml-parser-state
:text-hook
#'
(
lambda
(
string
seed
)
(
cons
string
seed
))))
(
result
(
start-parse-xml
in
state
)))
(
apply
#'
concatenate
'string
(
nreverse
result
))))
;;;; eof
\ No newline at end of file
test/tracer.lisp
View file @
d81401ac
;;;; -*- mode: lisp -*-
;;;;
;;;; $Id:
count
er.lisp,v 1.1
.1.1
2004/06/
07 18:49
:5
9
scaekenberghe Exp $
;;;; $Id:
trac
er.lisp,v 1.1 2004/06/
11 08:20
:5
8
scaekenberghe Exp $
;;;;
;;;; A simple SAX tracer example that can be used to understand how the hooks are called
;;;; A simple
S
SAX tracer example that can be used to understand how the hooks are called
;;;;
;;;; Copyright (C) 2004 Sven Van Caekenberghe, Beta Nine BVBA.
;;;;
...
...
@@ -18,28 +18,33 @@
(
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
))))
(
let
((
new-seed
(
cons
(
1+
(
car
seed
))
(
1+
(
cdr
seed
)))))
(
trace-xml-log
(
car
seed
)
"(new-element :name ~s :attributes ~:[()~;~:*~s~] :seed ~s) => ~s"
name
attributes
seed
new-seed
)
new-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
))))
(
let
((
new-seed
(
cons
(
1-
(
car
seed
))
(
1+
(
cdr
seed
)))))
(
trace-xml-log
(
car
parent-seed
)
"(finish-element :name ~s :attributes ~:[()~;~:*~s~] :parent-seed ~s :seed ~s) => ~s"
name
attributes
parent-seed
seed
new-seed
)
new-seed
))
(
defun
trace-xml-text-hook
(
string
seed
)
(
trace-xml-log
(
car
seed
)
"(text :string ~s :seed ~s)"
string
seed
)
seed
)
(
let
((
new-seed
(
cons
(
car
seed
)
(
1+
(
cdr
seed
)))))
(
trace-xml-log
(
car
seed
)
"(text :string ~s :seed ~s) => ~s"
string
seed
new-seed
)
new-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
)
:seed
(
cons
0
0
)
;; seed car is xml element nesting level
;; seed cdr is ever increasing from element to element
:new-element-hook
#'
trace-xml-new-element-hook
:finish-element-hook
#'
trace-xml-finish-element-hook
:text-hook
#'
trace-xml-text-hook
)))
...
...
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