New to XML need help

Questions about XML that are not covered by the other forums should go here.
sherzaad
Posts: 3
Joined: Mon Jun 05, 2017 7:18 pm

New to XML need help

Post by sherzaad »

Hi,

I'm new here and new to xml

Basically have this xml code at the moment:

Code: Select all

<?xml version="1.0" encoding="utf-8" standalone="yes"?><document>
<userealtime>False</userealtime>
<event category="Interaction" time="05/06/17 15:39:59.162"> Run.Pressed=False</event>
<event category="Interaction" time="05/06/17 15:40:00.060"> File.SaveAs.IO=C:\My Documents\Waveforms\20170605-0002.psdata</event>
</document>
the above code saves file 20170605-0002.psdata to the specified file location.

what I would like to be able to do is instead of having a static filepath string as above, I would like to add the systemtime (current PC time) to the filename.

Can anyone please help me with writing that bit of code? Thanks
Radu
Posts: 9048
Joined: Fri Jul 09, 2004 5:18 pm

Re: New to XML need help

Post by Radu »

Hi,

And how is that XML document generated? Is it manually modified? Maybe you can create the XML document on the spot before using it.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
sherzaad
Posts: 3
Joined: Mon Jun 05, 2017 7:18 pm

Re: New to XML need help

Post by sherzaad »

Hello Radu,

thank you for your reply.

the XML file was auto-generated by the application (picoscope). Similar to excel you can record macros in picoscope but instead of VBA, it saves the steps executed as xml.

I would like to now modify the script generated to basically add a timestamp each time a file is saved so as not to overwrite existing files as it would do with the xml code i have provided.
Radu
Posts: 9048
Joined: Fri Jul 09, 2004 5:18 pm

Re: New to XML need help

Post by Radu »

Hi,

Using Oxygen (or an open source XSLT processor) you can apply an XSLT stylesheet like this:

Code: Select all

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>

<xsl:template match="event[contains(text(), 'File.SaveAs.IO=')]">
<!-- Copy its attributes -->
<xsl:message><xsl:value-of select="current-time()"/></xsl:message>
<event>
<xsl:copy-of select="@*"/>
<!-- And modify the save output value -->
<xsl:value-of select="substring-before(text(), '.psdata')"/>
<xsl:text>-</xsl:text>
<xsl:value-of select="format-time(current-time(), '[H][m][s]')"/>
<xsl:text>.psdata</xsl:text>
</event>
</xsl:template>
</xsl:stylesheet>
over your XML document to add the current time of day to the output file name pattern.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
sherzaad
Posts: 3
Joined: Mon Jun 05, 2017 7:18 pm

Re: New to XML need help

Post by sherzaad »

Hello Radu,

Thank you for the script. That helps a lot.
Post Reply