SAX-like
apps in PHP
While there is no official implementation of the Simple API for XML
(SAX) in PHP, PHP does provide a SAX-like method for working with both
local and remote XML files. In this article, author Nicholas Chase shows
you how to work with XML files in PHP by building and setting handler
functions and creating a parser. He demonstrates SAX in PHP with a page-building
exercise in which he crafts a page based on the result of an Amazon
Web Services query. (2003 March 04)
The
Web's future: XHTML 2.0
Over the years, HTML has only become bigger, never smaller, because
new versions had to maintain backward compatibility. That's about to
change. On 5 August 2002, the first working draft of XHTML 2.0 was released
and the big news is that backward compatibility has been dropped --
the language can finally move on. So, what do you as a developer get
in return? How about robust forms and events, a better way to look at
frames and even hierarchical menus that don't require massive amounts
of JavaScript. (2002 Sept. 17)
Tip:
Call JavaScript from an XSLT style sheet
XSLT style sheets allow you a great deal of freedom in manipulating
the data in your original XML document. There are times, however, when
you really want to do actual programming, and the XSLT recommendation
is designed to allow that through the use of extensions. These extensions
take the form of functions and elements, and can be written in any language
the processor supports. One of your options is to embed JavaScript within
the style sheet, either directly or as an external file. (2002 April
25)
Tip:
Control white space in an XSLT style sheet
Because the style sheet and the source document in an XSLT transformation
have different rules regarding white space stripping, it often seems
as though the production of spaces and line breaks has no rhyme or reason
in the process. This tip shows you how to control the production of
white space in a transformation's result, which can lead to documents
that more closely align with your requirements. (2002 Nov. 20)
Tip:
Customize a DTD with parameter entities
Creating a Document Type Definition (DTD) and using it to validate your
document is a good way to ensure that the data fits a particular structure.
In some cases, however, you want to give users some control over the
structure. Parameter entities enable you to create a structure that
allows a document author to choose from two or more possible DTD structures
without giving that person control over the actual DTD. (2002 July 10)
Tip:
Grab headlines from a remote RDF file
In this tip, Nick shows you how to retrieve syndicated content from
RDF and RSS files and convert it to headlines for your site. (2002 April
04)
Tip:
Include external information with general entities
General entities enable XML authors to conveniently include not only
characters that would be difficult to represent directly, but also information
that must be repeated. They also enable you to import information from
another file, as well as from another location. This tip shows you how
to include external information through the use of general entities.
(2002 July 25)
Tip:
Make choices at runtime with XSLT parameters
Extensible Stylesheet Langauage Transformations provide the ability
to perform sophisticated manipulation of data as it is transformed from
one form to another. You can increase their capabilites even further
through the use of parameters that can be specified at runtime. This
tip takes a basic look at using parameters and conditional statements
in an XSLT style sheet. (2002 Aug. 07)
Tip:
Outputting HTML from an XSL style sheet
Because HTML is so similar to XML, it should be fairly straightforward
to create an XSLT style sheet that outputs HTML. Unfortunately, the
differences between HTML and XML that do exist can cause pages to be
displayed incorrectly in older browsers. This tip discusses those differences,
and explains how to use XSLT's output element to resolve the issues
they create. (2002 May 17)
Tip:
Send and receive SOAP messages with JAXM
In this tip, author and developer Nicholas Chase shows you how to use
the Java API for XML Messaging (JAXM) to simplify the process of creating
and sending SOAP messages. (2002 April 12)
Tip:
Set an XSL style sheet based on XML content
Using Extensible Stylesheet Language Transformations (XSLT) is often
the easiest way to transform your XML data from one form into another,
as it allows you a great deal of flexibility without having to change
an application. On occasion, however, you may run into a snag because
the style sheet to be used is based on the content of the document itself.
This tip discusses two ways to base your choice of style sheet on the
XML document -- the style sheet processing instruction and the data
itself. (2002 May 02)
Tip:
Stop a SAX parser when you have enough data
A SAX parser can be instructed to stop midway through a document without
losing the data already collected. This is one of the most commonly
mentioned advantages of a SAX parser over a DOM parser, which generally
creates an in-memory structure of the entire document. In this tip,
you'll parse a list of recently updated weblogs, stopping when you've
displayed all those within a particular time range. (2002 June 26)
Tip:
Traversing an XML document with a TreeWalker
XML's Document Object Model provides objects and methods that enable
a developer to navigate a document's tree, but typically the process
involves NodeLists and recursive methods
that make it easy to get lost within the structure. The DOM Level 2
Traversal module provides a new object, the TreeWalker,
which simplifies this process and makes navigation more reliable. This
tip demonstrates the process of determining whether a TreeWalker
is available and how to use it to extract information from a document.
(2002 Oct. 23)
Tip:
Use a SAX filter to manipulate data
The streaming nature of the Simple API for XML (SAX) provides not only
an opportunity to process large amounts of data in a short time, but
also the ability to insert changes into the stream that implements business
rules without affecting the underlying application. This tip explains
how to create and use a SAX filter to control how data is processed.
(2002 Oct. 18)
Tip:
Use imports and includes to override XSLT templates
Extensible Stylesheet Language Transformations (XSLT) provide two different
ways to combine several style sheets in the transformation of a single
source document. In the process, it's almost inevitable that more than
one template will apply to a single node. Which template is actually
applied depends on whether and how the template has been included in
the main style sheet. This tip explains how to use these conflict resolution
rules to give users control -- but not too much control -- over
styling issues. (2002 Nov. 13)
Tip:
Using a DOM NodeFilter
XML's DOM Level 2 Traversal module provides two new objects, the TreeWalker
and the NodeIterator, which simplify the
process of navigating a Document. More than
that, the module defines a NodeFilter, which
can be used to programmatically control what Nodes
are visible to the TreeWalker or NodeFilter.
This tip shows you how to create a NodeFilter
as well as a Traversal object that uses it. (2002 Nov. 06)
Tip:
XSL transformations to and from a SAX stream
The Transformation API for XML (TrAX) simplifies the process of performing
XSL transformations by creating a situation where you only need to create
the source, style, and result objects, then manipulate them using a
Transformer object. When sources and results are DOM nodes or files,
it's easy. But what if you want to transform to or from a SAX stream?
This tip shows you how to use SAX streams as both the source and destination
of an XSL transformation. (2002 July 03)