Qlik Community

QlikView App Development

Discussion Board for collaboration related to QlikView App Development.

Announcements
If you are a Qlik Insight Bot user, join this collaborative group: JOIN GROUP
Contributor II

Load xml file other than 0kb file

Hi All,

I have a bunch of xml files and some of them are 0kb files. I want QlikView to load only the once that are either more than 0kb size or atleast contains some data. Whenever I try to load all files i encounter an error as below:

XML document must have a top level element.

On line number: 0. On column number: 0. System ID: file:///..TaskResults/TaskResult_*.xml.

Files:

Load

..

..

Thanks for you help in advance.

1 Solution

Accepted Solutions
Highlighted
Contributor II

Re: Load xml file other than 0kb file

So I found a solution :

The problem is only while reading 0kb/ Corrupt XML file.

You can you something like below:

set ErrorMode=0;

{ Then your Load statement }

if  (ScriptError = 1) then

    exit script;

    end if

    set errormode=1;

View solution in original post

8 Replies
Highlighted
Honored Contributor II

Re: Load xml file other than 0kb file

Why dont you put..

set errormode = 0;

HTH

Sushil

Highlighted
Honored Contributor II

Re: Load xml file other than 0kb file

You can easily check the file size before load:

if filesize(filename) > 0 then

...

end if

Highlighted
Contributor II

Re: Load xml file other than 0kb file

set errormode = 0;

will work,however the problem is it will ignore all the errors. I might never know if there is any-other issue.

Highlighted
Contributor II

Re: Load xml file other than 0kb file

I have tried this solution but for some reason it never worked for me. I would be very glad if u can post me the script.

I'm still rookie so need ur help..

Highlighted
Valued Contributor II

Re: Load xml file other than 0kb file

For each vFileName in Filelist ('FilePath\*.xls')

     

      load * where Size > 24;

      Load *,

         '$(vFileName)' as FileName,

        SubField( SubField( '$(vFileName)','\',-1),'.',1) as FileType,

       Floor( FileSize('$(vFileName)')/1024) AS Size

      From [$(vFileName)];

     

   Next vFileName

Highlighted
Honored Contributor II

Re: Load xml file other than 0kb file

Hi.

It seems that you load the files using wildcard.

But to check the file size for each file before load you have to write the loop explicitly.

The easiest way is to use foreach + filelist as described in help and add the condition:

for each FileName in filelist('TaskResults/TaskResult_*.xml')

     if filesize('$(FileName)')>0 then

          load

               *

          from [$(FileName)] ...;

     end if

next FileName;

Highlighted
Contributor II

Re: Load xml file other than 0kb file

So I found a solution :

The problem is only while reading 0kb/ Corrupt XML file.

You can you something like below:

set ErrorMode=0;

{ Then your Load statement }

if  (ScriptError = 1) then

    exit script;

    end if

    set errormode=1;

View solution in original post

Highlighted
New Contributor III

Re: Load xml file other than 0kb file

I have a question with this.  Do you set up this piece of code after every load statement in your tab?

set errormode=0; - at the top of your tab

after each load statement - add

if  (ScriptError = 1) then

    exit script;

    end if

    set errormode=1;

I'm trying to understand the process and just making sure I am setting this up correct.

Thanks