Overview

This presentation describes the use of the SystemWeaver Script Language with a focus on XML generation. Examples and exercises are provided.

Course Type

Suitable for class training or for self study.

Course Length

Approximately 2 hours to half-day course. 

Prerequisites

Exercises

The answers to all exercises can be found in the swExplorer ribbon tab Report Training>Answers under XML.

 


Note: This presentation does not cover the complete set of functionality.

Introduction

The XML format is widely known as an exchange format for information. As a response to that, the SystemWeaver Report generation script language is equipped with the capability of generating such formats. This course will introduce the XML generation capabilities of SystemWeaver. After completing this course, explore all available features by using the SystemWeaver Help accessed by clicking the ? in the swExplorer or by taking the next available course.

 

XML Editor

XML formats are created in the XML Editor. To access it, select an item in the tree, click on the View drop-down list, select XMLs and select Sandbox:

 


The XML generation capabilities of SystemWeaver are composed of the following constructs:

  • <XDocument>
  • <XElement>
  • <XAttribute>
  • <Text>
  • <Description>
  • <XDefaultNamespace>


As with all configurable items, when you are satisfied with your script or to check on its progress, switch from the Definition to the View tab to see the results.


<XDocument>

The <XDocument> tag describes the root element of the XML document generated. It has an Attribute ”name=” that sets the name of the root element.


Example:


<XDocument name="RootElement"> 

</XDocument>




<XElement>


The <XElement> tag is used to define XML Elements within the <XDocument> tag. It has an Attribute ”name=” that sets the name of the element. <XElement> tags can be nested inside each other.


Note: XML element names may not contain blank spaces.


Example:


<XDocument name="RootElement"> 

  <XElement name="Specification">

     <ForEachPart type="XESX">                     

       <DefObj>

         <XElement name="#{Name}”/> 

       </DefObj> 

     </ForEachPart>

  </XElement>

</XDocument>



Bildresultat för exercise icon freeExercise 1 - XML Elements

  1. Open Item x0400000000000292.
  2. Open the XML Editor.
  3. For Vehicle Architecture, define an XML with Xelements that replicate the structure of the structure tree. 

Expected result: 


<XAttribute>

The <XAttribute> tag is used to define attributes of XML elements. It has an attribute ”name” that sets the name of the attribute and an attribute ”value” that defines the actual attribute value. One <XElement> can have many attributes.


Example:


<XDocument name="RootElement">  
  <XElement name="Specification">
    <ForEachPart type="XESX">                    
    <DefObj>
      <XElement name="#{Name}">
        <XAttribute name="handle" value="#{Handle}"/>
        <XAttribute name="version" value="#{Version}"/>
      </XElement>
      </DefObj>      
    </ForEachPart>
  </XElement>
</XDocument>



Bildresultat för exercise icon freeExercise 2 - Attributes

  1. Open Item x0400000000000292.
  2. Open the XML Editor.
  3. Using Exercise 1 as a starting point, add an attribute on every XElement for the handle, i.e., the unique ID of a SystemWeaver object, for every item. 

Expected result: 



<Text>

The <Text> tag is used to define text inside an <XElement>. 


Example: 


<XDocument name="RootElement"> 

  <XElement name="Specification">

    <Text>#{Name} : #{Version}</Text>

  </XElement>

</XDocument>




Bildresultat för exercise icon freeExercise 3 - Text 

  1. Open Item x0400000000000292.
  2. Open the XML Editor.
  3. Using Exercise 2 as a starting point, add an XElement on components and requirements containing the name of the item using a text tag.  

Expected result: 


<Description>

The <Description> tag is used to print the content of the Description field into an <XElement>. The format attribute has 3 options:

  • ”plain” exports the Description as plain text. 
  • ”xhtml” exports the Description in XHTML format version 1.0.
  • "reqif" exports the Description in XHTML format version 1.1.


Tip: When choosing one of the XHTML formats, the ”prefix” attribute can be used to specify which XML namespace prefix to use for the generated XHTML. Note that this namespace prefix must have been declared in the file already.


Example: 


<XDocument name="RootElement"> 

  <XElement name="Requirement">

   <Description format="plain"/>

  </XElement>

</XDocument>



Note: This is not the tag used for Description in reports.


Bildresultat för exercise icon freeExercise 4 - Description Field

  1. Open Item x0400000000000292.
  2. Open the XML Editor.
  3. Using Exercise 3 as a starting point, add an XElement on requirements containing the Description in plain text.  

Expected result (screenshot purposefully cut-off at bottom):


<XDefaultNamespace>

The <XDefaultNamespace> tag adds a default name space to the XDocument element. 


Example:


<XDocument name="RootElement"> 

  <XDefaultNamespace uri="ANameSpace"/>

</XDocument>


The purpose of using an URI is to give the namespace a unique name. However, companies often use the namespace as a pointer to a web page containing namespace information.


What's Next?

We hope that you are pleased with this course and are ready to generate XML. You can extend your knowledge by practicing the numerous scripting options described in the SystemWeaver Script Language Reference section in the Help. Additional training in the SystemWeaver Script Language is available upon request.