Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
mjayachandran
Creator II
Creator 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
mjayachandran
Creator II
Creator II
Author

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
sushil353
Master II
Master II

Why dont you put..

set errormode = 0;

HTH

Sushil

whiteline
Master II
Master II

You can easily check the file size before load:

if filesize(filename) > 0 then

...

end if

mjayachandran
Creator II
Creator II
Author

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.

mjayachandran
Creator II
Creator II
Author

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..

nizamsha
Specialist II
Specialist II

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

whiteline
Master II
Master II

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;

mjayachandran
Creator II
Creator II
Author

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;

ngosz4074
Contributor III
Contributor III

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