You can create a simple XML file that can be viewed in a text editor, browser or XML editor that echoes out all of the elements in a GoldSim model. This file contains the name, type, description and path for each element, and specifically illustrates the model hierarchy. As of GoldSim 14, the XML also includes the definitions of all Data elements. It does not, however, include the definition (e.g., input values, units) for any other elements besides the Data element type.
You can export the Model Inventory file by selecting File | Save Inventory… from the main menu. When the XML file is exported by Goldsim, the xml file has no stylesheet is specified. There are many tools available for viewing and parsing the XML file as-is. These can easily be found online. However, if you want to view the XML file in a format aligned with GoldSim's "Containment" view or "Class" view, follow the steps outlined in this article.
To understand what the 2 different styles look like, let's consider a very simple model file (as illustrated in the browser):
Figure 1 - GoldSim Browser Window |
In this example, Container1 contains a Data element named A, an Expression element named B, and a Container named Container2. Container2, in turn, contains a Data element named C. The Data element C is a vector type with 3 items called Zone10, Zone20, and Zone30.
When you execute the “Save Inventory…” command from the File menu, the following XML file is created in a specified directory. The XML file can be viewed in a browser or text editor. The default XML code for the above example model is shown below:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<GSM>
<!-- Model Inventory generated by GoldSim 15.0.0156 -->
<Global>
<File>C:\...\Model Inventory Example.gsm</File>
<Author>Jason Lillywhite</Author>
<Created>6/6/2024 11:54:48 AM</Created>
<Modified>6/6/2024 11:54:48 AM</Modified>
</Global>
<Model>
<Container type="Container" typeID="0" id="Model" desc="The base container for the project" path="\">
<Elements>
<Container type="Container" typeID="0" id="Container1" desc="" path="\">
<Elements>
<Container type="Container" typeID="0" id="Container2" desc="" path="\Container1\">
<Elements>
<Element type="Data" typeID="1" id="C" desc="" path="\Container1\Container2\">
<Input id="Definition" type="Value" order="Scalar" orderID="0" unit="">
<Equation>0.0</Equation>
</Input>
</Element>
</Elements>
</Container>
<Element type="Data" typeID="1" id="A" desc="" path="\Container1\">
<Input id="Definition" type="Value" order="Scalar" orderID="0" unit="">
<Equation>0.0</Equation>
</Input>
</Element>
<Element type="Expression" typeID="3" id="B" desc="" path="\Container1\" />
</Elements>
</Container>
</Elements>
</Container>
</Model>
</GSM>
To view the XML file with the Containment or Class formatting you must embed the Model Inventory xml code into a new stylized XML file. The steps to do this are described in the following section.
Embed Model Inventory inside Stylized XML
We provide two XML template files (download links below this article) that provide the XML with properties that align with the Containment or Class view, depending on which file you choose.
Note: The Containment and Class views are features that are already available in GoldSim’s browser window (see Figure 1). Even a well styled Inventory file will not show as much context about the model's structure and functionality as what the GoldSim software interface already provides. |
To embed the Model Inventory XML code into a stylized XML, follow these steps:
- Download one of the stylesheet files (either Containment.xslt or Class.xslt) using the links at the bottom of this article.
- Open the *.xslt file in a text and save the file as "my_inventory.xml" (or your own name). It should look something like what is shown below.
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<?xml-stylesheet href="#style" type="text/xsl" ?>
<GSM>
<!-- Insert your Model Inventory XML here... -->
<Stylesheet>
<xsl:stylesheet version="1.0" id="style" xml:id="style" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<!-- Some code not shown. -->
</xsl:template>
</xsl:stylesheet>
</Stylesheet>
</GSM> - Open the Model Inventory XML file generated by GoldSim.
- Select the and sections of the code and copy to the clipboard as shown below:
- Open "my_inventory.xml" created in step 2.
-
Paste the content of your clipboard just below the <GSM> tag (shown in bold below):
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<?xml-stylesheet href="#style" type="text/xsl" ?>
<GSM>
<Global>
<File>C:\V4152_ReliabilityPMReplace.gsm</File>
<Author>aburns</Author>
<Created>6/3/2024 11:02:10 AM</Created>
<Modified>7/28/2020 3:30:22 PM</Modified>
</Global>
<Model>
<Container type="Container" typeID="0" id="Model" desc="The base container for the project" path="\">
<!-- Remainder of Model Inventory goes here. -->
</Container>
</Model>
<Stylesheet>
<xsl:stylesheet version="1.0" id="style" xml:id="style" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<!-- Remainder of Stylesheet goes here. -->
</xsl:template>
</xsl:stylesheet>
</Stylesheet>
</GSM> - Note the code shown above excludes details for brevity.
Viewing the Styled XML
Now that you understand how to embed the Model Inventory XML into the template file, you can expect to see views similar to the examples shown below.
If we choose the Containment style (start with the containment.xml template), the styled XML file will show an organization in terms of Container hierarchy. The Inventory of the example described above will appear as shown below when starting with the containment.xml template (in Edge browser):
GoldSim Model Inventory - Containment FormatModel Root
|
As can be seen, this stylesheet formats the XML file emphasizing the containment hierarchy. Note values are displayed only for the Data elements.
If we choose the Class style (start with the containment.xml template), the styled XML file will show an organization in terms of Class (type of element). The Inventory of the example described above will appear as shown below when starting with the class.xml template (in Edge browser):
GoldSim Model Inventory - Class FormatContainers
Data Elements
Expression Elements
|
As can be seen, this stylesheet formats the XML file by element type.
To use these styles, download the example templates using the links below.
Comments
0 comments
Please sign in to leave a comment.