| Home | Lua | C-Talk | Z-Script | Notes |
Tutoial
Examples
Plug-in
References

A 10 Minutes Lesson on XML Script for zeGraph

zeGraph includes a special parser that recognizes predefined XML tags for creating zeGraph objects and calling their functions. The parser let you use XML as a script language to visualize data. While features of the XML script for zeGraph are not as rich as those of the Lua binding, programming involved in writing a XML script is minimal.

I. 3-Rules of XML

Like HTML, XML is composed of plain text that contains tags to give meanings to the contents between them; but unlike HTML, one can define his own tags and, at the same time, have to interpret those tags in one way or another.

You only have to remember three XML rules in writing a script for zeGraph:

  1. Make sure the open and closing tags are correct, e.g., <ze_render>...</ze_render>;
  2. Put as many comments as you like between <!-- and -->;
  3. A tag may have attributes which consists of key and value , e.g., <ze_scene name="scene1"> and the value must be quoted even if it is a number.

You may use MS explorer to verify XML format. For that purpose, please use <?xml version="1.0" encoding="ISO-8859-1" ?> as the first line. For more details on XML format, please refer to http://www.w3schools.com/xml/ and http://www.xml.com/.

II. A Simple Example

<ze_graph>
  <ze_render>
    <size>300, 300</size>
      <ze_scene>
        <ze_node name="root">
          <ze_polygon>
            <type>triangles</type>
            <ze_vertex>
              <append>
              -100, -100, 0, 100, -100, 0, 0, 100, 0
              </append>
            </ze_vertex>
            <ze_color>
              <append>
              0, 0, 1, 1,  0, 1, 0, 1, 1, 0, 0, 1
              </append>
            </ze_color>
          </ze_polygon>
        </ze_node>
      </ze_scene>
    <show>any</show>
  </ze_render>
</ze_graph>

III. 9 Rules of XML Script for zeGraph

  1. <ze_graph> must be used as the root tag to initialize zeGraph.
  2. When an object is created inside another (the parent), it will be assigned or added to the parent. In the example, the scene is add to the render; the node named "root" is assigned to the scene as the root node; and so on.
  3. A tag not prefixed with ze_ invokes a call to an object function. In the example, <size> under <ze_render> sets the size of the render object, which determines the image size.
  4. A parameters between tags can be separated by a comma, or one or more space characters, a parameter is not allow to contain space character even if it is intended to be used as a string.
  5. However, parameters passed to a function through XML attributes can have space characters.
  6. A object may have a name on creation, which may be re-used later.
  7. A render object can only have scene objects as children; a scene object can only have a node object as the root node; and a node or plot object can have any number of objects of any type as children.
  8. A shape objects of point, line, and polygon may only have objects of vertex, color, normal, and texcoord as children.
  9. Any object may be created under tag <ze_graph>.

IV. <include> and <use>

The <include> tag allows you to load scripts from other files. You can use this feature to load fine-tuned parts of script to the current script.

The <use> tag make any named object as the current object and then any function call refers to the object.

V. Data File Format

Data to be imported from a text file must be formated as follows:

  1. Starts a comment line with #.
  2. If a line starts with %, characters after it will be recognized as a dataset identifer.
  3. Data must follow the % line immediately.

VI. Learn From Examples

A 10 minutes lesson can't cover everything. Look into the examples for more uses of XML Script for zeGraph.

VII. Execute Script

  1. At the DOS prompt, use the command "zs.exe filename".
  2. Almost all programming language has a function for executing a shell command. For example, you can use the statement exec("ze.exe filename") in a PHP program.
  3. For MS PowerPoint, refer to the FAQ.