XML Explained (includes sample download)

XML (Extensible Markup Language) is a flexible markup language which is able to define objects and styles for entire web pages. The idea behind using XML to configure web pages is to create uniformity and simplicity of development throughout a web application.
It is possible to completely format, and script an entire page using entirely the XML capabilities of the PowerPac. The only Action needed is the one used to actually load the XML file which does the rest of the work for you. We can assist you in writing your XML configuration files.
A simple XML document:
ToolBook and XML:
XML Editors:
Experimentation Is the Best Teacher
It is possible to completely format, and script an entire page using entirely the XML capabilities of the PowerPac. The only Action needed is the one used to actually load the XML file which does the rest of the work for you. We can assist you in writing your XML configuration files.
A simple XML document:
- XML documents are text-based documents that contain tags that match in some way the elements on the HTML page. Extracting the contents of these tags provides the instructions to the XML interpreter how to format and display the page and what other dependencies should be loaded.
- Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<page>
<config>
<stylesheet>
../media/config.css
</stylesheet>
<setPageContentPosition>
<![CDATA[
{ left : 30, top : 30, width : '', height : '', addScrollBars : '', transparentPageBG : 42 }
]]>
</setPageContentPosition>
</config>
<Heading_1>
<pgStyleObject>
<![CDATA[
{ theStyle : "border, fontFamily, fontSize, fontStyle, fontWeight",
propVal : "0px none, Tahoma, 16pt, italic, bold" }
]]>
</pgStyleObject>
<htmlText>
<![CDATA[
XML Configuration Demonstration
<span class="copyright">
©2015 PG Software Development — Clifton L. Sleger
</span>
]]>
</htmlText>
<userProperty>
{ prop : "className", val : "heading_1", get_set : "set" }
</userProperty>
</Heading_1>
<body_frame_1>
<htmlText>
<![CDATA[
<div class="container">
<p style="margin-top:0px;">
This page demonstrates the methods used to configure a ToolBook page using CSS and XML configuration
files. Essentially, every element on the page may be configured, though there is a balance between
what <i><u>can</u></i> be configured and what <i><u>should</u></i> be configured.
</p>
<p>
The config.xml file included with this example contained fully commented sections that you can
use to figure out your specific configuration requirements. You can load as many XML files as
needed in your project and load them as necessary. During loading, any functions in the XML files
are executed at the same time.
</p>
<p>
XML files get cached in memory and will remain accessible to your application throughout the browser
session. The browser memory cache is much faster than its disk cache. Plus the server only needs to
deliver the XML file(s) ONCE per session which saves bandwidth and load time while navigating
between pages of your application.
</p>
<p>
You can create custom XML files and use the Actions Editor to parse the results. This is beyond the
reach of this basic tutorial.
</p>
<p>
To create XML files, you simply use a text editor. However, it is best to use one that has provisions
for working with XML files (i.e.: syntax highlighting, etc.). The one we use is called SynWrite and is
freely available. Other XML editors include NotePad++ and PSPad. The one you choose to use is entirely
based on preference and ease of use for you.
</p>
<p>
<b>NOTE:</b> You cannot open content with XML file configurations in IE from your local hard drive. Use
Firefox for all you development testing and then upload the content to a server for final testing in
other browsers.
</p>
</div>
]]>
</htmlText>
<pgStyleObject>
{ theStyle : "padding, overflowY, borderRadius, boxShadow",
propVal : "20px, auto, 20px, 1px 1px 8px 3px #333333" }
</pgStyleObject>
<pgTBObjSet>
{ myProperty : "user", myValue : "This is a user event on \"body_frame_1\"", myDelay : 3000 }
</pgTBObjSet>
</body_frame_1>
</page>
A typical XML file that could be used to configure a ToolBook page may look like this:
The page this defined by the above XML contains ONLY TWO fields and requires only ONLY ONE ACTION to load the XML using XMLHttpRequest(). The XML instructs the interpreter to load a single stylesheet which defines classes that determine how the content in each field will look.
You can view the page here: http://www.pgsoftwaretools.com/powerpac/assessments/xml/basics
Our original ToolBook page looks as simple as this! The XML document shown above contained the page content and handled sending one trigger to display a message prompt.
The entire PowerPac Help API is driven by XML files like this one! Editing a portion of a web application often simply involves editing the XML document which defines the page rather than going into author mode of ToolBook, making the change, and then re-exporting the entire application. In addition, exports are much faster since the page content need only be provided in XML files and the ToolBook application simply supplies the structure (or framework) for the page elements referred to the XML.
ToolBook and XML:
- ToolBook exports are NOT XML capable by design. However, the essence of adding this ability has existed for a long time. The PowerPac enables developers to completely define entire pages using XML files via the function XMLHttpRequest(). This function is able to retrieve the XML data files, parse them, and read the content in such a way as to style the ToolBook page.
- The PowerPac implementation of XML uses the browser's memory cache to put the XML data into memory so that it only is read ONCE per session. Thereafter, the data is instantly available making pages load much faster than normal.
- Microsoft IE does not allow developers to view XML driven content from the local hard drive. However, Firefox does and this is the preferred way to test your content before placing on the web server for final testing.
- XML files should be all placed in a common folder. They could be named based on the name of each page they configure but that is up to you.
- Use the PowerPac DHTML Export utility to flag the XML folder for inclusion in the export of the application.
- XML documents can be used to run other JavaScript and trigger objects, send user events, and perform many other practical tasks. Usually they are loaded with the page, however they can be retrieved at any time the services they provide are needed.
- XML documents can greatly lighten the Action code needed to drive an exported ToolBook page.
XML Editors:
- Choose a good XML editor to create the XML files. While they can be created in notepad, other text editors are designed to automatically close tags and color-code section elements and markup, thus making the entire document easier to read.
Some XML editor recommendations (all of which are freely available):
SynWrite (our preferred XML editor)
NotePad++ (well known and used by XML and web developers)
PSPAD (a good choice but lacks code folding which often comes in handy)
Experimentation Is the Best Teacher
- We have included for download the example cited above as a zip file that you can download and try. The XML included in the zip file is much larger than ordinary as we have fully commented each section to explain what it does and how it relates to the ToolBook page. Once you get a handle on using XML, you will never look back. XML files can be used to create mult-language setups and they can be stored in online databases to create different versions of a web application.