New to XML need help

Questions about XML that are not covered by the other forums should go here.
sherzaad
Posts: 3

New to XML need help

Mon Jun 05, 2017 7:30 pm

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: 5093

Re: New to XML need help

Tue Jun 06, 2017 1:49 pm

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

Re: New to XML need help

Tue Jun 06, 2017 2:44 pm

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: 5093

Re: New to XML need help

Tue Jun 06, 2017 3:43 pm

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

Re: New to XML need help

Tue Jun 06, 2017 6:40 pm

Hello Radu,

Thank you for the script. That helps a lot.

Return to “General XML Questions”

Who is online

Users browsing this forum: No registered users and 1 guest