checking a files existence
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 2
- Joined: Thu Jan 08, 2009 2:17 am
checking a files existence
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:
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.
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>

-
- Posts: 501
- Joined: Mon Feb 03, 2003 10:56 am
Re: checking a files existence
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.
All the best,
Dan
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>
Dan
Return to “General XML Questions”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service