YOUR SOURCE FOR SOLIDWORKS 3D CAD ENGINEERING SOFTWARE

SOLIDWORKS PDM Forms Series Part 3: XML as Forms

SOLIDWORKS PDM Tech Tip

Written by: Bryce Hooper, Application Engineer

In case you missed the earlier parts, check out Part 1 on Excel and Part 2 on Word.

To conclude the series on PDM and EC forms, we’ll discuss something that not everyone is familiar with and most aren’t quite sure what it does. XML, or the Extensible Markup Language, can be used to store data. What does XML do exactly? Well, according to the source for web standards, W3 Schools, XML does nothing. That’s right. It does nothing.  However, it does store and allows us to organize data. For example, we can look at my EC form.

This form in the end will look very similar to the forms used in the first and second installments of this blog series. But to start, we have this:

<?xml version=”1.0″ encoding=”UTF-8″?>
<EC_Form>
                <EC_Number>17020006</EC_Number>
                <EC_Part_Number>A0004</EC_Part_Number>
                <EC_Notice_Date>2017-02-18</EC_Notice_Date>
                <EC_Department>Painting</EC_Department>
                <EC_Old_Rev>A</EC_Old_Rev>
                <EC_New_Rev>B</EC_New_Rev>
                <EC_Description_of_Change>Change paint color to blue</EC_Description_of_Change>
                <EC_Reason_for_Change>Green no longer attainable</EC_Reason_for_Change>
                <EC_Effected_Parts>A0004</EC_Effected_Parts>
                <Signatures>
                                <Creator>BKH</Creator>
                                <Created_Date>2017-02-18</Created_Date>
                                <EC_Approval_ENG></EC_Approval_ENG>
                                <EC_Approval_ENG_Date></EC_Approval_ENG_Date>
                                <EC_Approval_MFG></EC_Approval_MFG>
                                <EC_Approval_MFG_Date></EC_Approval_MFG_Date>
                                <EC_Approval_QUAL></EC_Approval_QUAL>
                                <EC_Approval_QUAL_Date></EC_Approval_QUAL_Date>      </Signatures>
</EC_Form> 

So what do we have here? Well, we can see with the starting tag that we have an EC form. Everything within that tag is data for that EC Form. Going down the line we find the same information that we had in the previous forms, just with a different look. It’s still readable, but it isn’t necessarily pretty. There are a few things to understand about this data.

According to W3schools.com:

  • XML was designed to be read and understood by both machine and human.
  • XML was designed to store and transport data.
  • XML was designed to be self-descriptive

These things seem to make sense when we look at our data. Our tags aren’t difficult to read, they seem to be labeled to make sense. And clearly this is storing data. It even does so in a very small format. (This file is about 920 bytes, as opposed to a 26 kilobytes file in Word. Not a huge file either way, but the difference is still large.)

W3 Schools also goes on to mention that XML is designed to be a similar markup language as HTML. As we all should know, webpages are made of HTML and allow us to make nice looking forms and pages. There must be a way to combine the two… but we’ll get to that later.

It is important to know, that XML does not have any pre-defined tags.  The tags shown in my examples are made up by me, and are nothing you have to stick with.

With that in mind, we will continue by setting up the variables inside of PDM.

Edit Variable in SOLIDWORKS PDM

The block name for this file type is quite simple. It is just XML. Same for the file type. The Attribute names can get a little… tricky. The SOLIDWORKS help goes more into what is possible, but I will start here with what I have in this image. We’ve already looked at the structure of my XML document. We saw that an EC_Form tag encompasses the whole form. From there we have children tags. This is reflected in the Attribute name. We start at the root level, and add the child levels after a slash (“/”). For this case it is “EC_Form/EC_Old_Rev”. My example above also has some tags buried 3 levels deep. These will look similar to this “EC_Form/Signatures/EC_Approval_ENG”.

Note: We cannot have any spaces in the names of our attributes in XML. The spaces cause issues interpreting the files.

Since we have this mapped, we will need a base template before the data card will automatically enter our data.

What is important, is that we create any root tags so that their children tags and be given values and that we have our most important header tag.

<?xml version=”1.0″ encoding=”UTF-8″?>
<EC_Form></EC_Form>

With this little bit of information, PDM can write the rest.

So… this looks nothing like a form. We can’t present this to anyone. What more can we do?  Similar to HTML, which has CSS to stylize; XML has XSL. This is the eXtensible Stylesheet Language. With this, and an additional tag, we can convince our XML document to look presentable.

Here we can write a little bit of HTML and CSS in an XSL format to help us display our data. My form isn’t too complicated, just a simple table and some formatting. I won’t go too in depth on how to write this as the focus on this is the XML as a form. However, I will provide my sample code.

 

<?xml version=”1.0″ encoding=”UTF-8″?>
<xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”>
                <xsl:template match=”/”>
                  <html>
                                <style>
                                p.title
                                {
                                                text-align:center;
                                                font-size:28.0pt;
                                                line-height:107%;
                                                margin-top:0in;
                                                margin-right:0in;
                                                margin-bottom:8.0pt;
                                                margin-left:0in;
                                                line-height:107%;
                                                font-family:”Calibri”;
                                }
                                td.label
                                {
                                                background-color:black;
                                                color:white;
                                                border:solid windowtext 1.0pt;
                                                padding:0in 5.4pt 0in 5.4pt
                                                valign:middle;
                                                align:center;
                                                font-family:”Calibri”;
                                }
                                td.value
                                {
                                                background-color:white;
                                                color:black;
                                                font-family:”Calibri”;
                                }
                                </style>
                                <body>
                                                <xsl:for-each select=”EC_Form”>
                                                                <p class=”title” align=”center”><img width=”166″ height=”84″ src=”../../Templates/DASILogoJan30.png”/>Engineering Change Notice</p>
                                                                <table border=”1″ cellspacing=”0″ cellpadding=”0″ align=”center”>

                                                                <tr>
                                                                  <td class=”label” width=”120″>Part Number:</td><td class=”value” width=”150″><xsl:value-of select=”EC_Part_Number”/></td>
                                                                  <td class=”label” width=”120″>Old Rev:</td><td class=”value” width=”150″><xsl:value-of select=”EC_Old_Rev”/></td>
                                                                </tr>

                                                                <tr>
                                                                  <td class=”label” width=”120″>Date of Notice:</td><td class=”value” width=”150″><xsl:value-of select=”EC_Date_of_Notice”/></td>
                                                                  <td class=”label” width=”120″>New Rev:</td><td class=”value” width=”150″><xsl:value-of select=”EC_New_Rev”/></td>
                                                                </tr>

                                                                <tr>
                                                                                <td class=”label” width=”270″ colspan=”2″>Description of Change:</td>
                                                                                <td class=”label” width=”120″>Department:</td><td class=”value” width=”150″><xsl:value-of select=”EC_Department”/></td>
                                                                </tr>

                                                                <tr>
                                                                                <td class=”value” width=”540″ height=”100″ colspan=”4″ valign=”top”><xsl:value-of select=”EC_Description_of_Change”/></td>

                                                                </tr>

                                                                <tr>
                                                                                <td class=”label” width=”540″ colspan=”4″>Reason for Change:</td>
                                                                </tr>

                                                                <tr>
                                                                                <td class=”value” width=”540″ height=”100″ colspan=”4″ valign=”top”><xsl:value-of select=”EC_Reason_for_Change”/></td>
                                                                </tr>

                                                                <tr>
                                                                                <td class=”label” width=”540″ colspan=”4″>Effected Parts:</td>
                                                                </tr>

                                                                <tr>
                                                                                <td class=”value” width=”540″ height=”100″ colspan=”4″ valign=”top”><xsl:value-of select=”EC_Effected_Parts”/></td>
                                                                </tr>

                                                                <tr>
                                                                                <td class=”label” width=”120″>Creator:</td><td class=”value” width=”150″><xsl:value-of select=”Signatures/Creator”/></td>
                                                                                <td class=”label” width=”120″>Created Date:</td><td class=”value” width=”150″><xsl:value-of select=”Signatures/Created_Date”/></td>
                                                                </tr>

                                                                <tr>
                                                                                <td class=”label” width=”120″>Engineering Approval:</td><td class=”value” width=”150″><xsl:value-of select=”Signatures/EC_Approval_ENG”/></td>
                                                                                <td class=”label” width=”120″>Approved Date:</td><td class=”value” width=”150″><xsl:value-of select=”Signatures/EC_Approval_ENG_Date”/></td>
                                                                </tr>

                                                                <tr>
                                                                                <td class=”label” width=”120″>Mfg Approval:</td><td class=”value” width=”150″><xsl:value-of select=”Signatures/EC_Approval_MFG”/></td>
                                                                                <td class=”label” width=”120″>Approved Date:</td><td class=”value” width=”150″><xsl:value-of select=”Signatures/EC_Approval_MFG_Date”/></td>
                                                                </tr>

                                                                <tr>
                                                                                <td class=”label” width=”120″>Quality Approval:</td><td class=”value” width=”150″><xsl:value-of select=”Signatures/EC_Approval_QUAL”/></td>
                                                                                <td class=”label” width=”120″>Approved Date:</td><td class=”value” width=”150″><xsl:value-of select=”Signatures/EC_Approval_QUAL_Date”/></td>
                                                                </tr>
                                                </table>
                                                </xsl:for-each>
                                </body>
                  </html>
                </xsl:template>
</xsl:stylesheet>

This code, will result in a form that looks roughly like this:

Engineering Change Notice - Created with XML

Note that the values of the XML tags are displayed in this form through a special tag. This tag <xsl:value-of select=”Signatures/EC_Approval_MFG”/> retrieves the value specified in the select statement. Now that we have a stylesheet defined, we need to tie it into our XML document. This is another easy tag across the top that looks like this:

<?xml-stylesheet type=”text/xsl” href=”../../Templates/ECN.XSL”?>

The href tag is the path to the XSL file. In order for this to work, we either need to put this in a central location and reference it in an XML template, or copy it each time. For the best benefit of an XML form, I recommend putting it in a central location. My location is 2 levels above where my EC forms will reside, in the templates folder.

From here, we can take our standard approach to creating templates. Create a template card to capture inputs and fill in a serialized EC number. And, of course, we can create workflow actions to fill in values along the way.

As with any method, there are some pros and cons to this. As with the other methods I’ve discussed in this series, I’ll break down some of what I see.

Pros:

  • Previews update without opening and re-saving the file
  • Forms require no software beyond a web browser to be able to view or print
  • Once a format is set, a change can be cascaded to all existing forms by altering the XSL*
  • No known issues with variable types

Cons:

  • Requires that someone know HTML/CSS to write
  • Requires a folder structure to allow consistent reference paths if keeping the XSL in a central location
  • Likely to be a new concept, so would require converting existing forms

 

*Changing the format of all existing forms can be avoided by creating a second stylesheet, leaving the first in place for old documents.

 

 

DASI Knowledge Base - Tips & Tricks

 

This entry was posted in Tips & Tricks, Uncategorized and tagged , , , , , , . Bookmark the permalink.