Arbitrary TextIn the Hello World example, the text replaced was associated with an HTML element; specifically, the <p> element. It didn't have to be the <p> element; it could have been any element. But what if the text that needs to be replaced is not delimited by an HTML element? The bad news is that Dynamator requires an HTML element. It can't locate arbitrary text. The good news is that there is an HTML 4.0 element created specifically for this purpose: <span>. The <span> element can be used to wrap arbitrary text. According to the HTML spec, <span> has no effect on the rendered browser output. The PageThis example extends the original Hello World example slightly. HTMLOnce marked up with a <span> element, the file looks like this: ArbitraryText.html (updated)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Hello World</title> </head> <body> <p>The greeting for today is <span id="DynamicText">Hello world</span> </body> </html> Other FilesBecause this file uses the same ID value as the original HelloWorld example, and the behavior is the same, we could use the same Dynamator file. But because Dynamator expects the Dynamator file to have the same base name as the HTML file, we need to create a file with the name 'ArbitraryText.dyn'. This file could use the directive '<include file="HelloWorld.dyn"/> to reuse the original content. Running dynamateAs in the first example, the HTML file needs to be processed by dynamate: prompt=> java dynamate ArbitraryText.html Generated JSP fileThe above command produces the following file. Changes to the original HTML are highlighted. ArbitraryText.jsp
In ActionIf you are viewing this page in a servlet engine, you can see the generated page in action. ObservationsBecause they provide a structured way to address arbitrary portions of an HTML document, the <span> and <div< elements are essential to site building with Dynamator. This lesson only hints at an extremely powerful capability of Dynamator. Dynamator's loose coupling to HTML and it's <include> mechanism, combined with a strong naming convention, can enable a tremendous degree of reuse. |
||||||
Page last updated 01 April 2004 |
Copyright 2001-2004 by Jay Dunning. All rights reserved. |
hosted by |