xsxp(3tcl) | Amazon S3 Web Service Utilities | xsxp(3tcl) |
xsxp - eXtremely Simple Xml Parser
package require Tcl 8.4
package require xsxp 1
package require xml
xsxp::parse xml
xsxp::fetch pxml path ?part?
xsxp::fetchall pxml_list path ?part?
xsxp::only pxml tagname
xsxp::prettyprint pxml ?chan?
This package provides a simple interface to parse XML into a pure-value list. It also provides accessor routines to pull out specific subtags, not unlike DOM access. This package was written for and is used by Darren New's Amazon S3 access package.
This is pretty lame, but I needed something like this for S3, and at the time, TclDOM would not work with the new 8.5 Tcl due to version number problems.
In addition, this is a pure-value implementation. There is no garbage to clean up in the event of a thrown error, for example. This simplifies the code for sufficiently small XML documents, which is what Amazon's S3 guarantees.
Copyright 2006 Darren New. All Rights Reserved. NO WARRANTIES OF ANY TYPE ARE PROVIDED. COPYING OR USE INDEMNIFIES THE AUTHOR IN ALL WAYS. This software is licensed under essentially the same terms as Tcl. See LICENSE.txt for the terms.
The package implements five rather simple procedures. One parses, one is for debugging, and the rest pull various parts of the parsed document out for processing.
An element of path scans the children at the indicated level for the n'th instance of a child whose tag matches the part of the element before the hash sign. If an element is simply "#" followed by digits, that indexed child is selected, regardless of the tags in the children. Hence, an element of "#3" will always select the fourth child of the node under consideration.
part defaults to "%ALL". It can be one of the following case-sensitive terms:
For example, to fetch the first bold text from the fifth paragraph of the body of your HTML file,
xsxp::fetch $pxml {body p#4 b} %PCDATA
For example, pxml_list might be the %CHILDREN of a particular element, and the path and part might select from each child a sub-element in which we're interested.
This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category amazon-s3 of the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist]. Please also report any ideas for enhancements you may have for either package and/or documentation.
When proposing code changes, please provide unified diffs, i.e the output of diff -u.
Note further that attachments are strongly preferred over inlined patches. Attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar.
dom, parser, xml
Text processing
2006 Darren New. All Rights Reserved.
1.0 | tcllib |