Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML Parsing error

Status
Not open for further replies.

CryoGen

MIS
Apr 15, 2004
86
0
0
US
OK, I'm fairly new to XML and FileMaker. I keep getting an error: "XML Parsing Error: The main document cannot be empty". I'm a little fuzzy on the syntax.

The import I'm trying to accomplish has three parts: the FMP database, an XML output file from a third-party program that churns out the file names in a given Windows XP directory, and an XSL stylesheet that is supposed to transform the XML file to a workable format.

To-Be-Imported XML File: xml_listing.xml

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hdlg:filesystem SYSTEM "[URL unfurl="true"]http://www.hdlg.info/XML/filesystem.dtd">[/URL]
<hdlg:filesystem xmlns:hdlg="[URL unfurl="true"]http://www.hdlg.info/XML/filesystem">[/URL]
   <hdlg:folder name="pdfs" url="file:/c:/pdfs/">
      <hdlg:file name="FEB248.pdf" size="17407400" type="unknown" url="file:/c:/pdfs/FEB248.pdf">
      </hdlg:file>
      <hdlg:file name="FEB249.pdf" size="13918425" type="unknown" url="file:/c:/pdfs/FEB249.pdf">
      </hdlg:file>
      <hdlg:file name="FEB250.pdf" size="38914" type="unknown" url="file:/c:/pdfs/FEB250.pdf">
      </hdlg:file>
      <hdlg:file name="FEB251.pdf" size="21109720" type="unknown" url="file:/c:/pdfs/FEB251.pdf">
      </hdlg:file>
      <hdlg:file name="FEB252.pdf" size="35559" type="unknown" url="file:/c:/pdfs/FEB252.pdf">
      </hdlg:file>
      <hdlg:file name="FEB253.pdf" size="7288156" type="unknown" url="file:/c:/pdfs/FEB253.pdf">
      </hdlg:file>
      <hdlg:file name="FEB254.pdf" size="11409973" type="unknown" url="file:/c:/pdfs/FEB254.pdf">
      </hdlg:file>
      <hdlg:file name="pdf_listing.html" size="7368" type="unknown" url="file:/c:/pdfs/pdf_listing.html">
      </hdlg:file>
      <hdlg:file name="xml_listing.xml" size="0" type="unknown" url="file:/c:/pdfs/xml_listing.xml">
      </hdlg:file>
   </hdlg:folder>
</hdlg:filesystem>

XSL Stylesheet: k4_import.xsl

Code:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
    <xsl:output indent="yes" method="xml"/>
    <xsl:template match="k4_file_names">
        <FMPXMLRESULT xmlns="[URL unfurl="true"]http://www.filemaker.com/fmpxmlresult">[/URL]
            <ERRORCODE>0</ERRORCODE>
            <PRODUCT BUILD="08-14-2007" NAME="FileMaker Pro" VERSION="8.0v3"/>
            <DATABASE DATEFORMAT="M/d/yyyy" LAYOUT="" NAME="k4_file_names.fp7" RECORDS="10" TIMEFORMAT="h:mm:ss a"/>
            <METADATA>
                <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="name" TYPE="TEXT"/>
                <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="size" TYPE="TEXT"/>
                <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="type" TYPE="TEXT"/>
                <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="url" TYPE="TEXT"/>
            </METADATA>
            <RESULTSET FOUND="10">
                <xsl:for-each select="k4_file_names">
                    <ROW MODID="0" RECORDID="{position()}">
                        <COL>
                            <DATA>
                                <xsl:value-of select="name"/>
                            </DATA>
                        </COL>
                        <COL>
                            <DATA>
                                <xsl:value-of select="size"/>
                            </DATA>
                        </COL>
                        <COL>
                            <DATA>
                                <xsl:value-of select="type"/>
                            </DATA>
                        </COL>
                        <COL>
                            <DATA>
                                <xsl:value-of select="url"/>
                            </DATA>
                        </COL>
                    </ROW>
                </xsl:for-each>
            </RESULTSET>
        </FMPXMLRESULT>
    </xsl:template>
</xsl:stylesheet>

I thought I had everything formatted properly, but I guess not. The database file has four fields: name, size, type and url. Here is the XML file I want to import, and and XSL stylesheet I want to use to do the import. I continue to get the error above. I can't figure out what's wrong, so any help is appreciated.
 
The stylesheet is looking for an element named "k4_file_names", which I don't see in the XML document here. Does FM do some sort of internal translation?

Phil Hegedusich
Senior Programmer/Analyst
IIMAK
-----------
Pity the insomniac dyslexic agnostic. He stays up all night, wondering if there really is a dog.
 
No, it might have more to do with ignorance. The stylesheet is calling "k4_file_names" ... which is the name of the database, but not the XML file. Might I be better off by naming the XML file "k4_file_names.xml"?
 
The stylesheet directive <xsl:for-each select="k4_file_names"> normally searches an XML document for every instance of an element identified in the select attribute.

So if I have an XML file like

<root name="myinfo">
<k4_file_names directory="mydirectory">
<file name="whatever" size="148KB">
<file....
</k4_file_names>
.
.
.

The for-each directive would find every element "k4_file_names" and, from there, can perform XSL actions on the attributes (such as directory) and sub-elements (such as file) that are found.

As I said before, I'm not familiar with the way that FM manages XML. Can the database generate an XML document or variable on which you can apply an XSL stylesheet?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top