NEW XML Features: v15

Using XMLHttpRequest() to configure entire ToolBook pages.

NEW XML Features: v15

Postby Clifton » Mon Feb 18, 2019 7:39 pm

It is now possible to declare a Javascript object or a Javascript array directly in your XML files. When your XML file is loaded from the server, object (or array) code that is found in the <![CDATA[ ... ]]> section will be automatically converted to an object (or array) as defined in your tag.
To declare a Javascript object with property/value pairs:
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<page>
    <automobile>
        <![CDATA[
            { "make" : "Honda",
              "year"   : "2019",
              "model" : "Civic",
              "miles" : "0",
              "price" : "$21,170" }
        ]]>
    </automobile>
    <automobile>
        <![CDATA[
            { "make" : "Toyota",
              "year"   : "2015",
              "model" : "Sienna Van",
              "miles" : "45,427",
              "price" : "$22,263" }
        ]]>
    </automobile>
    <automobile>
        <![CDATA[
            { "make" : "Chevrolet",
              "year"   : "2016",
              "model" : "Impala",
              "miles" : "44,217",
              "price" : "$16,100" }
        ]]>
    </automobile>
</page>

When the above XML is loaded, it will generate a user event with the following [value] parameter:
    [value]["automobile"][0]
    [value]["automobile"][0]["make"] => "Honda"
    [value]["automobile"][0]["year"] => "2019"
    [value]["automobile"][0]["model"] => "Civic"
    [value]["automobile"][0]["miles"] => 0
    [value]["automobile"][0]["price"] => "$21,170"
    [value]["automobile"][1]
    [value]["automobile"][1]["make"] => "Toyota"
    [value]["automobile"][1]["year"] => "2015"
    [value]["automobile"][1]["model"] => "Sienna Van"
    [value]["automobile"][1]["miles"] => "45,427"
    [value]["automobile"][1]["price"] => "$22,263"
    [value]["automobile"][2]
    [value]["automobile"][2]["make"] => "Chevrolet"
    [value]["automobile"][2]["year"] => "2016"
    [value]["automobile"][2]["model"] => "Impala"
    [value]["automobile"][2]["miles"] => "44,217"
    [value]["automobile"][2]["price"] => "$16,100"

NOTE: The only requirement is that the tag name must be unique and NOT correspond to the name of an object on the page or a PowerPac function name.

The NEW feature allows even more flexibility when entering your XML data. For example, previously to accomplish the same result your XML would have been entered like this:
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<page>
    <automobile>
        <make>Honda</make>
        <year>2019</year>
        <model>Civic</model>
        <miles>0</miles>
        <price>$21,170</price>
    </automobile>
    <automobile>
        <make>Toyota</make>
        <year>2015</year>
        <model>Sienna Van</model>
        <miles>45,427</miles>
        <price>$22,263</price>
    </automobile>
    <automobile>
        <make>Chevrolet</make>
        <year>2016</year>
        <model>Impala</model>
        <miles>44,217</miles>
        <price>$16,100</price>
    </automobile>
</page>

In previous PowerPac releases, there was no provision for directly coding arrays and having the interpreter generate them from the code. Now you can directly code arrays as follows:
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<page>
    <myArray>
        <![CDATA[
            [ 16, 23, 100, 42, 86 ]
        ]]>
    </myArray>
</page>

The above XML would produce the following result:
    [value]["myArray"][0]  => 16
    [value]["myArray"][1] => 23
    [value]["myArray"][2] => 100
    [value]["myArray"][3] => 42
    [value]["myArray"][4] => 86

Creating and managing XML files makes working with ToolBook projects faster and easier because you generally do not have to export your project very often. Just edit a specific XML file and reload the book in your browser to see the result. Functions, user events, clicks, mouse events and just about any other type of handler can be built in your XML files. In many cases, XML enables you to create events that are not supported in the Actions system (e.g.: mouse down or mouse up events). Plus the XML files can handle non-ToolBook elements in the parent window.

Glad to help you customize things to work with your projects.
 
Clifton
Site Admin
 
Posts: 731
Joined: Tue Jan 14, 2014 1:04 am

Return to XML Configurations – Plugin Examples

Who is online

Users browsing this forum: No registered users and 1 guest

cron