The XML format is widely known as an exchange format for information. As a response to that, the SystemWeaver Script Language is equipped with the capability of generating such formats. This material introduces the XML generation capabilities of SystemWeaver.
Prerequisites
- Familiar with the SystemWeaver meta model building blocks (e.g., Items, Parts and Attributes)
- Familiar with the SystemWeaver Explorer Interface and common operations
- An installation of the SystemWeaver Explorer client (swExplorer)
- Knowledge of XML (A good resource is w3schools' XML tutorials)
- Familiar with the SystemWeaver Script Language
- The SWExtension.XhtmlDescription extension file is located in the Client's swExplorerExtensions directory
Note: This article does not cover the complete set of functionality. |
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.
<Document>
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>
<XComment>
The <XComment> tag is optional and can be used, together with <Text> to include comments in the XML output. The text value may include SystemWeaver Field Codes.
Example
<XDocument name="TopTag"> <XComment> <Text>My comment</Text> </XComment> </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>
<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>
<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>
<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. |
Note: <Description format="reqif"/> is deprecated. For improved XHTML generation use <Extension name="xhtmlDescription"/>. |
Example
<XDocument name="RootElement"> <XElement name="Requirement"> <Description format="plain"/> </XElement> </XDocument>
Note: This is not the tag used for Description in reports. |
<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?
You can extend your knowledge by practicing the numerous scripting options described in the SystemWeaver Script Language Reference Manual in the application Help. See Requirements Exchange (ReqIF), to learn more about exporting in ReqIF format.