skip to main content
Developing with design tools > Using the Designer > Data formats > Application data in XML files for JViews Diagrammer
 
Application data in XML files for JViews Diagrammer
You can import application data from an XML file provided that the XML elements conform to the diagram format.
The following code example shows the initial XML data file for the genealogy tree as loaded in Getting started.
Simple genealogy tree data and model in XML
 
<?xml version="1.0" encoding="UTF-8"?>
 
<!DOCTYPE diagram>
 
<diagram metadata="true" xmlns:sdm="http://www.ilog.com/JViews/SDM/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <person id="person_1">
    <property name="sex">male</property>
    <property name="sdm:y">264.91016</property>
    <property name="firstname">John</property>
    <property name="profession">teacher</property>
    <property name="deathdate">1960</property>
    <property name="sdm:x">35.429688</property>
    <property name="name">Smith</property>
    <property name="birthdate">1900</property>
  </person>
  <person id="person_2">
    <property name="sex">female</property>
    <property name="sdm:y">165.28516</property>
    <property name="firstname">Janet</property>
    <property name="deathdate">1970</property>
    <property name="sdm:x">35.429688</property>
    <property name="name">Whoop</property>
    <property name="birthdate">1903</property>
  </person>
  <couple id="couple_1">
    <property name="startdate">1920</property>
    <property name="sdm:y">215.09766</property>
    <property name="sdm:x">123.75</property>
    <property name="status">married</property>
  </couple>
<couplelink islink="true" id="couple_11" from="person_1" to="couple_1" />
  <couplelink islink="true" id="couple_21" from="person_2" to="couple_1" />
  <person id="person_3">
    <property name="sex">male</property>
    <property name="sdm:y">310.3828</property>
    <property name="firstname">Andrew</property>
    <property name="profession">engineer</property>
    <property name="deathdate">1995</property>
    <property name="sdm:x">214.79688</property>
    <property name="name">Smith</property>
    <property name="birthdate">1922</property>
  </person>
  <childlink islink="true" id="child_1_3" from="couple_1" to="person_3" />
  <person id="person_4">
    <property name="sex">female</property>
    <property name="sdm:y">119.8125</property>
    <property name="firstname">Mary</property>
    <property name="profession">Advocat</property>
    <property name="sdm:x">214.79688</property>
    <property name="name">Smith</property>
    <property name="birthdate">1924</property>
  </person>
 
 <childlink islink="true" id="child_1_4" from="couple_1" to="person_4" />
  <person id="person_5">
    <property name="sex">male</property>
    <property name="sdm:y">212.97656</property>
    <property name="firstname">Richard</property>
    <property name="profession">Writer</property>
    <property name="deathdate">1995</property>
    <property name="sdm:x">214.79688</property>
    <property name="name">Bilbot</property>
    <property name="birthdate">1920</property>
  </person>
<couple id="couple_2">
    <property name="startdate">1942</property>
    <property name="sdm:y">166.39453</property>
    <property name="enddate">1960</property>
    <property name="sdm:x">305.84375</property>
    <property name="status">divorced</property>
  </couple>
  <couplelink islink="true" id="couple_42" from="person_4" to="couple_2" />
  <couplelink islink="true" id="couple_52" from="person_5" to="couple_2" />
  <person id="person_6">
    <property name="sex">male</property>
    <property name="sdm:y">166.39453</property>
    <property name="firstname">Henry</property>
    <property name="profession">Driver</property>
    <property name="sdm:x">391.375</property>
    <property name="name">Bilbot</property>
    <property name="birthdate">1945</property>
  </person>
  <childlink islink="true" id="child_2_6" from="couple_2" to="person_6" />
  <person id="person_7">
    <property name="sex">male</property>
    <property name="sdm:y">26.648438</property>
    <property name="firstname">Jack</property>
    <property name="profession">Technician</property>
    <property name="deathdate">1997</property>
    <property name="sdm:x">214.79688</property>
    <property name="name">Johnson</property>
    <property name="birthdate">1925</property>
  </person>
  <couple id="couple_3">
    <property name="startdate">1960</property>
    <property name="sdm:y">73.23047</property>
    <property name="sdm:x">305.84375</property>
    <property name="status">married</property>
  </couple>
  <couplelink islink="true" id="couple_43" from="person_4" to="couple_3" />
  <couplelink islink="true" id="couple_73" from="person_7" to="couple_3" />
</diagram>
In this XML file:
*A link is a top-level XML element ( childlink or couplelin k) with the attribute isLink set to true and attributes from and to which refer to nodes defined in the same file.
*All other top-level XML elements are treated as nodes ( person and couple ).
*Properties are defined as children of a node or link element. Each property has a value.
*The sdm:x and sdm:y properties are x- and y-coordinates giving the location of a node.
Diagram format in XML
The root element of the diagram format in XML has the tag diagram.
In diagram format, there is an implicit data model. When data is read from an XML file, each XML element that is a child of the root element (each top-level element) is considered to be an object of the data model, specifically, a user-defined type.
The top-level elements are either links (attribute isLink is true) or nodes (attribute isLink is false ). Nodes and links must be distinguishable by different XML element names. They are loaded from the same file.
The top-level XML elements that are not links ( isLink attribute = false ) are represented by nodes in the diagram. The elements that are links ( isLink attribute = true ) are represented by links in the diagram.
The name of the XML element (the string after the opening “<”) becomes the value of the tag property of the the model object.
The following attributes can be defined on an XML element:
*The XML attribute id represents the object’s unique identifier (ID).
*The XML attribute isLink, when set to true, indicates that the model object is a link.
*The XML attributes from and to for a link designate the origin and destination. The values of these attributes are the IDs of the origin and destination nodes.
The data properties of the objects appear in the XML file as child elements of the top-level elements with the name (tag) property.
The name of the property is the value of the name attribute. The value of the property is the text of the element.
For example, the following line shows a property speed with the value 148.0:
 
<property name="speed">148.0</property>
Metadata in the XML data file
You can include metadata in the XML data file to store information about the data in general and about specific objects.
The root diagram element has a Boolean attribute metadata which indicates whether metadata is to be handled. The default value is true.
 
<diagram metadata="true"/>
Metadata is represented by elements with the sdm: prefix, indicating a specific SDM namespace.
There are two types of metadata:
*Object-related
*General
Object-related metadata
Object-related metadata can be included with a similar format to properties. The following example specifies a value for the metadata item x:
 
<property name="sdm:x">23</property>
General metadata
General metadata can be included in a dedicated RDF section.
A general metadata section in an XML data file
 
<diagram metadata="true" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
                     xmlns:dc="http://dublincore.org/"
     xmlns:sdm="http://www.ilog.com/JViews/SDM/" />
  <rdf:RDF>
   <rdf:Description about=".">
    <dc:Creator>
        <sdm:Pseudo>PhK</sdm:Pseudo>
        <sdm:Office>S023</sdm:Office>
    </dc:Creator>
   </rdf:Description>
  </rdf:RDF>
 
  ... (the remainder of the document represents the SDM model)
 
</diagram>
Note that if an XML file contains an element with the name rdf, then the metadata attribute of the diagram element is forced to true.

Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.