[This local archive copy mirrored from the canonical site: http://www.vrml.org/WorkingGroups/dbwork/vrmlxml.html, 980727; links may not have complete integrity, so use the canonical document at this URL if possible.]

Integrating XML and VRML:
A Technical Discussion

Daniel Lipkin
Oracle Corporation

Contents

Introduction
Background
Metadata
Visualization and Style Sheets
Next Steps

Introduction

VRML, the Virtual Reality Modeling Language, is the ISO standard for representing 3D on the Web. It provides a versatile platform for a variety of applications that use 3D as a central metaphor or interface. One of the strengths of VRML is its tight integration with a variety of other web technologies and its ease of incorporating the benefits of those technologies, from graphic, audio, and video formats to scripting languages and network protocols. Another powerful feature of VRML is its easy extensibility and ability to add new node types and capabilities to the base language.

One of the most significant new web standards to emerge recently is XML, the Extensible Markup Language. XML defines a standard format for representing and exchanging structured data on the web, enabling the use of a standard API, the Document Object Model (DOM), for managing that data, and the deployment of standard services for generating and viewing XML content. XML has already been widely adopted by an industry eager to overcome the limitations of HTML for structured data. XML is expected to become a standard means for delivering database-driven web content, and already serves as the basis for a variety of web applications, from metadata representation to domain-specific markup languages.

Although designed originally for different problem domains, the two technologies of VRML and XML have much to offer each other, and there are a variety of areas where tighter integration between the two can provide powerful benefits. Some existing work in this area already exists; for example, the Visual XML proposal for using XML and VRML to represent and display structured information spaces. This paper investigates additional potential areas of synergy and suggests useful next steps.

Background

A VRML file consists of a set of nodes that define the contents of a virtual world. The VRML Specification defines a set of 54 built-in nodes that provide the basic building blocks for all VRML worlds. VRML provides the ability to extend this base set of nodes using the PROTO mechanism. PROTOs allow the encapsulation and reuse of functionality as new node types, implemented via either pre-existing nodes or native browser extensions. PROTOs are the mechanism of choice for extending VRML's functionality and adding new features and capabilities to the language.

An XML file is a structured document consisting of elements that are denoted by tags. Whereas HTML defines a particular set of valid tags, XML documents may incorporate arbitrary markup as defined by the XML Specification. Typically, a particular application of XML will be based upon a specific definition of valid elements known as a Document Type Declaration (DTD). A DTD specifies the allowed sets of elements, the attributes of each element, and the valid content of each element. Elements may contain data content, that is, plain text, additional elements, or a combination of both. There are a variety of attribute types; one of the most common is the ID attribute, which serves to unqiuely identify an element within a document.

XML inherently contains no information about the visual display of its contents. The display of an XML document is determined by an XML style sheet, which contains instructions for translating an XML document into an HTML document. These style sheets are defined using Extensible Style Language (XSL), and a variety of tools are being developed to aid in creating and editing style sheets.

An XSL document consists of construction rules, containing patterns to identify particular elements in the source XML document, and actions for translating the specified elements into HTML content. Actions specify flow objects to create, which correspond to specific formatting tasks. Generating flow objects can be a recursive process, so that each element's children in turn define additional flow objects. In addition to flow objects, custom scripts can also be used to programatically determine formatting behavior.

XSL defines a set of core HTML flow objects, as well as more general DSSSL flow objects. While flow objects do not necessarily have to be expressed as HTML, they do fundamentally assume a two-dimensional, page layout model.

Metadata

Metadata is, simply put, the representation of data about data. There is a variety of types of and uses for metadata, from copyright and author information to detailed categorization schemes. Naturally enough, there are many areas where easy and flexible access to metadata would be useful to VRML authors. In fact, there have even been suggestions for a custom metadata node to extend the built-in WorldInfo node.

One of the main design goals of the Resource Description Framework (RDF) is to provide a robust and flexible system for metadata on the Web. RDF uses XML as its transport mechanism; that is, an RDF document is by definition an XML document. Therefore, rather than duplicating existing work by devising a custom metadata framework for VRML, it makes more sense to devise a system and syntax for VRML to work with any XML document. This allows VRML take advantage of RDF, as well as the variety of other applications based on XML. This approach leverages the rigorous design work of RDF and XML and the expected ubiquity of these formats.

A reasonable approach is to take the Document Object Model, the standard API for reading and writing XML and HTML documents, and support an appropriate subset of its features within VRML. This will enable a VRML author to extract data from any XML document and incorporate that data within an application's logic and scripts, using familiar VRML syntax.

In this case, we can reduce the scope of the problem by assuming that authors will only be reading existing XML documents. This means that the following operations defined by the DOM are the operations of interest:

We can further simplify the problem by imposing the restriction that only elements that have an "ID" attribute can be accessed. This does mean that our solution can only access a subset of an XML document and that care must be taken in designing documents so that all the relevant information is accessible. Because our design objective is to support the most common features of XML using VRML's high-level, script-like design philosophy, this is a reasonable trade-off. Similar reasoning leads us to collapse many of the individual DOM operations into combined operations.

We define the following VRML PROTO to express our interface:

EXTERNPROTO Metadata [ 
	exposedField MFString url [] 
	eventIn SFString elementID  
	eventOut MFString elementIDs
	eventOut SFString tagName
	eventOut MFString attributeNames 
	eventOut MFString attributeValues 
	eventOut MFString childElements 
	eventOut MFString childElementTypes 
	] 
"urn:inet:vrml.org:dbwork.Metadata"
The url field contains references to a list of XML documents. The strings in this field indicate multiple locations to search for data in decreasing order of preference. As a convenience, this field may also contain XML code in-line.

On initialization, and whenever the url field subsequently changes, the elementIDs event is generated. This event contains the ID values of the elements in the document for all elements that have an ID attribute explicitly specified.

The remaining events are generated whenever the elementID event is received and contain information about the specified element, if it exists.

tagName contains the string that is the element's name.

attributeNames contains a list of all attribute names defined for this element. attributeValues contains the corresponding attribute values.

childElement contains values of all child elements of the specified element, and childElementTypes defines the type of the child element. Valid values are:

childElementType contents of childElements
ELEMENT ID value of the element, or empty string if no ID is defined
TEXT Value of the text

Note that only elements and #PCDATA children are returned; processing instructions and comments are ignored.

As an example, consider the following simple XML document:

<?xml version="1.0"?>
<books id="vrml">
<book id="cmarrin" author="Chris Marrin" published="1997"> 
Teach Yourself VRML 2.0 in 21 Days 
</book> 
<book id="vrml20" author="Rikk Carey & Gavin Bell" published="1997"> 
The Annotated VRML 2.0 Reference Manual
</book> 
</books>
On initialization, the elementIDs eventOut is sent with a value of [ "vrml", "cmarrin", "vrml20" ].

An elementID eventIn of vrml would produce the following eventOuts:

Event Name Event Value
tagName book
attributeNames ["id"]
attributeValues ["vrml"]
childElements ["cmarrin", "vrml20"]
childElementTypes ["ELEMENT", "ELEMENT"]

An elementID eventIn of cmarrin would produce the following eventOuts:

Event Name Event Value
tagName book
attributeNames ["id", "author", "published"]
attributeValues ["cmarrin", "Chris Marrin", "1997"]
childElements ["Teach Yourself VRML 2.0 in 21 Days"]
childElementTypes ["TEXT"]

The following fragment of VRML code uses the Metadata node to retrieve the title of a specified book:

DEF books Metadata {
	url [ "books.xml" ]
	}

# script to generate a book ID
DEF S1 Script {
	eventOut SFString bookID
	url "javascript:
		function initialize() {
			bookID = 'cmarrin';
			}"
	}

# display text of book
Shape {
	appearance DEF white Appearance {
		material Material {
			diffuseColor 1 1 1
			}
		}
	geometry DEF book_name Text { 
		string [""] 
		fontStyle DEF Font FontStyle {
				size 2
				justify "MIDDLE"
				style "BOLD"
			}
		}
	}


ROUTE S1.bookID TO books.elementID
ROUTE books.childElements TO book_name.set_string
This example illustrates how easily VRML applications can access XML content and data using this proposed interface.

Visualization and Style Sheets

VRML is well-suited for the visualization of complex or multi-dimensional data, and is used for a variety of data visualization applications, from financial data analysis to web site navigation. However, while standards for data-driven VRML, such as the Recommended Practices for SQL Database Access, are beginning to emerge, most VRML files today remain static files generated on a one-time basis, unable to represent real-time or frequently changing data.

On the other hand, there are already a variety of technologies for the real-time generation of XML from live databases and other data sources, and it is safe to assume that this will be a major application of XML. Style sheets can then be used to translate this dynamic data into HTML. However, the current specification for style sheets is limited in that it focuses only on generating HTML. There are many cases where more robust visualizations of an XML document are desirable, visualizations such as those afforded by VRML. Thus, it is natural to extend XSL to also support the creation of VRML based on an XML document.

To achieve this support, the same model for construction rules and patterns applies, since these are solely used to select subsets of the source XML document for translation. However, some additional flow objects need to be defined to take advantage of the unique properties of VRML. These flow objects fall into two categories:

  1. PROTO mappings. Rather than limit the possible means of displaying XML, we allow any VRML PROTO instantiation based on XML content. This maximizes the flexibility of the system, since authors can design an arbitrary PROTO to encapsulate a visualization component, then instantiate that PROTO based on the contents of the XML document.

  2. Transformation mappings. Unlike HTML flow objects, which are simply placed one after the other on the page, VRML flow objects need to be placed in three-dimensional space. To accomodate this, we define a flow object to specify how objects are translated and rotated in space.

PROTO Mappings

There are two steps to defining flow objects for PROTO mappings. We must first define a PROTO node to be instantiated, and then define how the contents of the XML file map to the fields of the PROTO. Notice that this process is in one sense fundamentally different from style sheets that generate HTML: rather than maintaining the text of the document, and simply transforming from one set of markup to another, we are taking a subset of the document text and placing it into fields of nodes.

One approach is to define a new flow object called PROTO, used to specify the name of a PROTO definition. When this flow object is encountered, a VRML node of the specified type is created in the target document. Child elements in the XML document are then candidates for defining the values of fields. Field mappings are defined by specifying the name of the field in the action section, using the placement of the <children/> tag to specify the location of the target text within the generated field value.

As an example of how this might work, consider the following XML document containing information about stock data:

<?xml version="1.0"?>
<stocks>
<stock id="ORCL">
<symbol>ORCL</symbol>
<growth>10</growth>
<performance>9</performance>
<pe>5</pe>
</stock>
</stocks>
We wish to visualize this document as a three-dimensional graph. To accomplish this, we wish to map each stock element to a VRML PROTO named bar that represents a single bar in a 3D bar graph. This PROTO has the following interface:
PROTO bar [
	field SFInt32 x 0
	field SFInt32 y 0
	field SFInt32 z 0
	field MFString label [ "" ]
	]
The following XSL fragment could accomplish this mapping:
  <rule>
    <target-element type="stock"/>
	<PROTO>bar</PROTO>
	<children/>
  </rule>

  <rule>
    <element type="stock">
      <target-element type="growth"/>
    </element>
	x <children/>
   </rule>

  <rule>
    <element type="stock">
      <target-element type="performance"/>
    </element>
	y <children/>
   </rule>

  <rule>
    <element type="stock">
      <target-element type="pe"/>
   </element>
   z <children/>
   </rule>

    <element type="stock">
      <target-element type="symbol"/>
    </element>
	label "<children/>"
   </rule>
The above XSL rules generate a target bar node for each source stock node, and map the four child text elements to the four fields of the node. For the XML document above, this will create the following VRML node:
bar {
  x 10
  y 9
  z 5
  label "ORCL"
  }
Follow this link for the complete stock graph example. In this example, notice that we employ some useful conventions, such as placing the standard VRML header and the PROTO definition at the top of the generated file using the <root\> rule.

Transformation Mappings

The other new flow object is used to create Transform nodes in the target VRML document. While we could require all transform information to be explicitly defined in the user's PROTO, in practice this is such a useful and common operation that it makes sense to define additional syntax for it.

We define a new TRANSFORM flow object to indicate that a Transform node should be placed in the generated document. This flow object has two attributes. The increment_field attribute is used to specify one or more fields of the generated Transform node, in the format "field.component", for example, translation.z. The increment_value attribute is used to specify the amount by which the specified field of each Transform instantiation has its value incremented.

As an example, consider an XML document that displays some basic employee information, perhaps for use by a human resources application:

<?xml version="1.0"?>
<people>

<person>
<name>Smith</name>
<salary>1500</salary>
<years>14</years>
</person>

<person>
<name>Jones</name>
<salary>1800</salary>
<years>12</years>
</person>

<person>
<name>Johnson</name>
<salary>1200</salary>
<years>15</years>
</person>

</people>
Suppose we wish to graphically display this information using a three-dimensional icon for each person. Each icon should be displaced by a constant amount along the x axis. This can be accompished using the following XSL fragment:
  <rule>
    <target-element type="person"/>
	<TRANSFORM increment_field="translation.x" increment_value=10>
	<PROTO>EmpIcon</PROTO>
	<children/>
	</TRANSFORM>
  </rule>
Notice that we are using a PROTO named EmpIcon to represent an employee's icon.

We then use the same syntax as in the previous example to specify mappings for field values:

  <rule>
    <element type="person">
      <target-element type="name"/>
    </element>
	name [ "<children/>" ]
   </rule>

  <rule>
    <element type="person">
      <target-element type="salary"/>
    </element>
	salary [ "<children/>" ]
   </rule>

  <rule>
    <element type="person">
      <target-element type="years"/>
    </element>
	years 10 <children/> 10
   </rule>
This generates the following VRML, consisting of Transform nodes wrapped around PROTO instantiations:
Transform {
  translation 0 0 0
  children [
    EmpIcon {
      name [ "Smith" ]
      salary [ "$1500" ]
      years 10 14 10
      }
    ]
   }

Transform {
  translation 10 0 0
  children [
    EmpIcon {
      name [ "Jones" ]
      salary [ "$1800" ]
      years 10 12 10
      }
    ]
   }

Transform {
  translation 20 0 0
  children [
    EmpIcon {
      name [ "Johnson" ]
      salary [ "$1200" ]
      years 10 15 10
      }
    ]
   }
Follow this link for the complete human resources example.

The above simple cases serve to illustrate the power and versatility of this approach and the usefulness of being able to graphically represent arbitrary XML documents.

Next Steps

This paper proposes two areas where integration of XML and VRML provides powerful benefits and suggests syntax for the VRML and XSL constructs needed to achieve this integration. There are obviously many steps remaining to improve and formalize these proposals, address missing functionality, standardize the proposals, and implement them.

The next step on the standards path is to introduce these proposals into the working group process of the respective standards bodies, the VRML Consortium and the World Wide Web Consortium. The working groups are the appropriate forums for developing a consensus and drafting a formal standards proposal.

As the XSL proposal in particular impacts both standards, it should be pursued through both the Enterprise Technology Working Group and the XML Working Group in conjunction. This work also provides an excellent opportunity to establish closer coordination and cooperation between the two standards bodies, hopefully paving the way for future cooperative efforts.

In addition, simultaneous efforts should be undertaken to provide working implementations.

The Metadata node can be implemented as a PROTO wrapper around a custom Java script, which will provide a useful tool for initial testing and evaluation. VRML browser authors should also implement this node as a native EXTERNPROTO extension within their browsers.

An initial implementation of the proposed VRML flow objects might use a preprocessor to translate an XSL document with VRML flow objects into an XSL document with custom ECMAScript functions for generating VRML text. The generated document can then be processed by any compliant XSL processor. Additionally, it may be useful to provide this functionality through server-side components, such as a Java Servlet, so that server-generated XML can be seamlessly delivered as VRML code to clients. Eventually, XSL will support an extensibility mechanism which can be used to directly support these new flow objects. In the long term, just as HTML browsers are now being extended with support for XML and XSL, VRML browsers should seamlessly process XML and XSL and automatically display the resulting VRML.

Another critical aspect to making these technologies usable is the availability of appropriate authoring tools. In this case, a new category of authoring tool is called for, one that combines the 3D modeling and composition of VRML authoring tools with the style sheet generation of XSL authoring tools. Such a tool would be the basis of a new and powerful paradigm for web-based data visualization applications.


This document can be found at http://www.vrml.org/WorkingGroups/dbwork/vrmlxml.html
Please contact the author at dlipkin@us.oracle.com with questions or comments.