This was fun 🙂
The project that I’m working on it pretty complex and I did talk about couple of things that I’m doing at my current client during KScope, some of might even saw the videos. Hey it is pretty exciting stuff.
I’m fortunate that they are the first client to use the cutting edge (upcoming) feature in PBCS and I’m part of that team.
Now this post is nothing related to that (in some way yes it is related), this one is about stylizing the LCM artifact listing (or understand what is in that file!!!).
I was assigned a task of finding out the objects existing in PBCS (specially forms), now if this was on-prem I could fire an SQL command and easily get the list. Hey hey this is PBCS, we don’t allow any backend queries here.
Only option left is to use the Artifact Snapshot listing.xml and go through the list of XML files and generate the list, well you all know that I’m a lazy guy and I don’t like doing that. (going through the files if they are under too many folders is a big task)
Now we all know that listing.xml is an XML file and contains the listing information of the current LCM (yeah we all know that, otherwise why would someone name it with an XML extension ;))
How can we look at that file, it’s all in one single line?. Well I get it, I use Notepad ++ and with the XML highlighting it is easier to read the file. (well it is still a single line!!!).
So here comes a nice plugin in Notepad++ (I did promise that I’ll soon write a post on all the useful plugins that I use in Notepad++, patience dear reader, it is coming :))
I use a plugin called XML Tools in Notepad++ and if you are working with XML files then that is a great plugin to have.
Open listing.xml file in Notepad++
Select XML tools from plugins and select “Pretty print (XML only – with line breaks), oh yes there are lot of options, you can enable the syntax check and it’ll let you if you didn’t close any headers/ syntax issues in the XML file.Here comes the magic now
The big one liner became a pretty readable XML file now. Okay I admit that I’m still nowhere near my assigned task, I’m nearing there.
I don’t know how many of you’ve heard about XSLT (if you’ve not; here is the link), it is a language used for transforming XML files.
Couple of things to keep in mind before starting with XSLT (This is my version of XSLT and XML explanation, you might find differences with the theory world ;))
You need to tell the language where to start the transformation and this is going to be nothing but the root of XML and in our case artifactListing (if you look at listing.xml the entire contents are within this node)
So we got our starting point, now you’ve two inner nodes inside artifactListing which are folder and resource (oh yeah it’s just those two) and their attributes.
Now I see you are getting where I’m going with this, if you don’t just be patient.
So all I’ve to do to get the list of forms is to create an XSLT and ask it to give me the following attributes for resource.
<?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> <body> <h2> Forms</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>Path</th> <th>Name</th> <th>Type</th> <th>Modified By</th> <th>Last Updated</th> </tr> <xsl:for-each select="artifactListing/resource"> <tr> <td><xsl:value-of select="@path"/></td> <td><xsl:value-of select="@name"/></td> <td><xsl:value-of select="@type"/></td> <td><xsl:value-of select="@modifiedBy"/></td> <td><xsl:value-of select="@lastUpdated"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
So let’s look at the xsl file
All I did in that code was
- Asked to loop through all resources (artifactListing/resource)
- While I’m at it asked it to return, path, name, type, modifiedBy and lastUpdated attribute values
Now to get the output, you can edit the xml file itself and add a line in the beginning as shown below or use XML Tools.
<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="artifact.xsl"?> <artifactlisting> <folder modifiedBy="" path="/Relational Data" pathAlias="/Relational Data" size="-1" type="folder"/>
If you opt to edit the xml, all you’ve to do after saving the file is to open the listing.xml in a browser
There you go, all resources neatly documented as a table. Now if you are not comfortable editing the file, you can use XML Tools.
Open XML Tools from Plugins -> Choose XSL Transformation.
It’ll ask for the XSL file
Select the file created and run the “Transform”. XML Tools will generate a new transformed file (which is an html). You can save the file as an html file and open that in a browser (well there is a plugin for previewing html in Notepad++, I’ll talk about that in next post)
Look at that!!! I can even get a list of Smart Lists, Dimensions and all the resources in entire PBCS world 🙂
Well getting all the form names is easy from here just filter on type for “Data Form”
Now if you want to get a list of folders from listing.xml, use the below given XSL
<?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> <body> <h2> Form Folders</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>Path</th> <th>Type</th> <th>Modified By</th> <th>Last Updated</th> </tr> <xsl:for-each select="artifactListing/folder"> <tr> <td><xsl:value-of select="@path"/></td> <td><xsl:value-of select="@type"/></td> <td><xsl:value-of select="@modifiedBy"/></td> <td><xsl:value-of select="@lastUpdated"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
Here is the output
I can use the filter “Form Folder” to get all data form folders 🙂
As my big brother from completely different set of parent says easy peasy lemon squeezy 🙂
One comment I received was why not use EXCEL to do this, EXCEL can create a schema for XML and show it in a table. Not that I didn’t try I didn’t like to format of it.
You’ll get folders and resources in the same table and you’ve to figure out which one is which (again not a tedious task). I just opted to go this route, because I thought this is more geekier 😉 more clean and more flexible (you can choose whether you want folders/resources, you can choose which attributes to pull