xml editor

Products

Features

  EPUB
Supported platforms

Supports Windows 7 & Mac OS X Lion

Ready for XML Editor data server software
W3C Member

checking a files existence

Questions about XML that are not covered by the other forums should go here.

checking a files existence

Postby melvis » Thu Jan 08, 2009 2:29 am

Complete noob with oXygen and not very familiar with XML to boot so bear with me. An application (that I cannot control) performs a data import using XML and external graphic files. The app goes line-by-line through the XML, finds the files then imports them from their stated location (typically a relative path bundled within a zip). The problem comes when a file is missing. At this point the application throws an exception and stops.

I'd like to get a report of all the missing files so I can make placeholders and continue with the import. An example of a media reference is below:

Code: Select all
<media display="visible">
            <label><![CDATA[New: Figure]]></label>
            <description/>
            <comments/>
            <keywords/>
            <mediafiles>
                 <mediafile>
                      <filename><![CDATA[./media/PD/bigpicture.png]]></filename>
                      <dpi/>
                      <width>200</width>
                      <mediatype>web</mediatype>
                  </mediafile>
            </mediafiles>
            <alttext/>
</media>


I'm not a programmer but have (years ago) used js and vbscript in the past to do projects like this. Am I right in assuming that oXygen can perform the task of creating the offending file report? Either way is better than looking through about 1 million lines and checking manually :( Any help is appreciated.
melvis
 
Posts: 2
Joined: Thu Jan 08, 2009 2:17 am

Re: checking a files existence

Postby Dan » Thu Jan 08, 2009 1:37 pm

After unzipping the content into a folder, you can apply the following XSL file over the XML document. It will generate a report with all the files that do not exist. Make sure you edit the first parameter from the "fpath" to match your folder.

Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
    xmlns:file="java:java.io.File">
    <xsl:output indent="yes"/>
    <xsl:template match="filename">

        <xsl:variable name="fname" select="string(.)"/>
        <!-- Change the first argument the your folder.-->
        <xsl:variable name="fpath" select="concat('/Users/dan/Desktop/',$fname)"/>
        <xsl:variable name="exists" select="boolean(file:exists(file:new($fpath)))"/>

        <xsl:if test="not($exists)">
            <not-existing>
                <xsl:value-of select="$fname"/>
            </not-existing>
        </xsl:if>
    </xsl:template>

    <xsl:template match="/">
        <report>
            <xsl:apply-templates select="//filename"/>
        </report>
    </xsl:template>
    <xsl:template match="text()"/>
</xsl:stylesheet>



All the best,
Dan
Dan
 
Posts: 182
Joined: Mon Feb 03, 2003 10:56 am

Re: checking a files existence

Postby melvis » Thu Jan 08, 2009 4:07 pm

I'll try it. Cheeers!
melvis
 
Posts: 2
Joined: Thu Jan 08, 2009 2:17 am


Return to General XML Questions

Who is online

Users browsing this forum: No registered users and 0 guests

XML Editor | XML Author | WYSIWYG Editors | Schema Editor | XSD Documentation | XSL/XSLT Editor | XQuery | XML Databases | SVN Client
© 2002-2011 SyncRO Soft Ltd. All rights reserved. | Sitemap | Privacy Policy | This website was created & generated with <oXygen/>® XML Editor