B4J Question Trouble Reading an XML File from the client side, while Web Site is managed by a B4J Server

Christos Dorotheou

Member
Licensed User
Longtime User
Hi to all,

I am trying to create a Web Site and I want to have a B4J (Non-UI application console / server application) as my Web Server.

The site I want to build is pretty simple and its purpose would be to display some local artists
paintings in a slide show manner.

I also would like to use B4J as my WebServer because I want to avoid setting up any other
dedicated Web Server such as MS IIS etc.

The visitors of the site are presented with a simple page which has 3 HTML select elemets
as Artist Name, Art Theme and Art Media Type, and according to what they choose
they can view the paintings of their selection in a slideshow.

Everything was straight forward, up to the point where I decided to populate these
HTML 'select' elements, from XML files which contain the 'options' of the HTML selections,
just to be more manageable later on during the maintenace of the site, instead of hardcoding
them in the html file.

I have accomplished these using javascript and Ajax and it works fine locally.
But when I try to access the site via the B4J server the XML files can not be located by the browser.

I get in the log file the following error:
"GET /artistslist.xml HTTP/1.1" 404 293 "http://localhost:51255/index.html"

This is the script using Ajax, that populates a <select> element having ID=cmbTheme:

B4X:
            <!--***** LOAD THEMES COMBO BOX *****    -->
            $.ajax({
                type: "GET",
                url: "themeslist.xml",
                dataType: "xml",
                success: function(xmlthemes) {
                    var optionsHtml = new Array();
                    var selectTheme = $('#cmbTheme');
                    $('dropdown', xmlthemes).each(function(){
                        $(this).find('themestyle').each(function(){
                            var value = $(this).attr('value');
                            var label = $(this).text();
                            optionsHtml.push( "<option class='ThemeStyles' value='"+ value +"'>"+label+"</option>");
                        });
                        optionsHtml = optionsHtml.join('');
                        selectTheme.append(optionsHtml);          
                    });                  
                },
                error: function() {
                    alert("An error occurred while processing THEMESLIST.XML file.");
                }
            });

and this is the ThemesList.xml file structure residing in www:

B4X:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<dropdown>
    <themestyle value="0">All</themestyle>
    <themestyle value="1">Abstract</themestyle>
    <themestyle value="2">Abstraction</themestyle>
    <themestyle value="3">Abstract expressionism</themestyle>
    <themestyle value="4">Lyrical Abstraction</themestyle>
    <themestyle value="5">Color field</themestyle>
    <themestyle value="6">Cubism</themestyle>
    <themestyle value="7">Surrealism</themestyle>
    <themestyle value="8">Conceptual Art</themestyle>
    <themestyle value="9">Pop Art</themestyle>
    <themestyle value="10">Realism</themestyle>
    <themestyle value="11">Photorealism</themestyle>
    <themestyle value="12">Hyperrealism</themestyle>
    <themestyle value="13">Minimalism</themestyle>
    <themestyle value="14">Futurism</themestyle>
    <themestyle value="15">Impressionism</themestyle>
    <themestyle value="16">Fauvism</themestyle>
    <themestyle value="17">Painterly</themestyle>
</dropdown>

I understand that this problem, is some kind of a restirction on accessing external files.

I would like to know if there is any way to make those XML files that reside on the server's
www folder accessible by the client.

I have also tried a different approach using 'XMLHttpRequest' but with no success.
I do not know if there is a need of some server side Handler for this to work.

Any help will be much appreciated.

Regards

Chris
 

Christos Dorotheou

Member
Licensed User
Longtime User
What is the xml file name?
artistslist.xml or ThemesList.xml or themeslist.xml?

Hi Erel,

The xml name is ThemesList.xml

I am sorry for the comfusing:

"GET /artistslist.xml HTTP/1.1" 404 293 "http://localhost:51255/index.html"

I just posted only one entry from the logs file.

In the log file there are 3 such instances, because I am using 3 XML files to populate 3 different <SELECT> elements

B4X:
0:0:0:0:0:0:0:1 -  -  [13/Aug/2014:12:30:03 +0000] "GET /images/themeslist.xml HTTP/1.1" 404 299 "http://localhost:51255/main1.html" "Mozilla/5.0 (Windows NT 6.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36"
0:0:0:0:0:0:0:1 -  -  [13/Aug/2014:12:30:03 +0000] "GET /images/artistslist.xml HTTP/1.1" 404 300 "http://localhost:51255/main1.html" "Mozilla/5.0 (Windows NT 6.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36"
0:0:0:0:0:0:0:1 -  -  [13/Aug/2014:12:30:03 +0000] "GET /images/medialist.xml HTTP/1.1" 404 298 "http://localhost:51255/main1.html" "Mozilla/5.0 (Windows NT 6.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36"

The file names of the XML files are: ArtistsList.xml, ThemesList.xml and MediaList.xml.

Is it a case sensitive issue ?

Regards

Chris
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…