473,480 Members | 1,847 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Loading XML config file for web page

TMN
Hi All

If I want to use an xml file to hold some config parameters for a web
page do I need to load it with JS
or is there a way of including it in the <head?

Thanks
Tim
Jun 27 '08 #1
5 2584
TMN wrote:
If I want to use an xml file to hold some config parameters for a web
page do I need to load it with JS
Yes, use XMLHttpRequest for best cross-browser support to load the file.
or is there a way of including it in the <head?
Only IE has a concept of a so called XML data island where you can load
XML data inside of a HTML document using an 'xml' element e.g.
<xml id="x1" src="file.xml"></xml>
But that is not supported by other browsers.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 27 '08 #2
TMN wrote:
Hi All

If I want to use an xml file to hold some config parameters for a web
page do I need to load it with JS
or is there a way of including it in the <head?
Use XMLHttpRequest to collect the data.
Jun 27 '08 #3
TMN
On May 14, 6:33 pm, The Magpie <use...@pigsinspace.co.ukwrote:
TMN wrote:
Hi All
If I want to use an xml file to hold some config parameters for a web
page do I need to load it with JS
or is there a way of including it in the <head?

Use XMLHttpRequest to collect the data.
Thanks - It just seems something like <xml id="x1" src="file.xml"</
xmlis so natural for a browser !!!

regards
Tim
Jun 27 '08 #4
joe
TMN <na******@gmail.comwrote:
>Hi All

If I want to use an xml file to hold some config parameters for a web
page do I need to load it with JS
or is there a way of including it in the <head?

Thanks
Tim

Here a sample how to load a page with Javascript.
Be adivsed that it returns immediately. So if you use it to intialize variables
do them in "whatever" function.

Here' what I mean (pseudocode):

line 0: ..
line 1: blah, blah;
line 2: loadXMLDoc(..); //loads a value to "myvar"
line 3: if (myvar==1)
line 4: blah, blah;
line 5: ...

When execution of code reaches Line 4 you'd expect "myvar" to have some value.
Not so! Caveat! "whatever" is executed (see below example code) when it's good
and ready. loadXMLDoc(..) returns immediately (well almost).



loadXMLDoc("http://www.yourhomepage.com/somefile.txt");

function loadXMLDoc(url)
{
xmlhttp=null;
if (window.XMLHttpRequest)
{// code for IE7, Firefox, Opera, etc.
xmlhttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlhttp!=null)
{
xmlhttp.onreadystatechange=whatever;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
else
{
alert("Your browser does not support it.");
}
}

function whatever()
{
if (xmlhttp.readyState==4)
{// 4 = "loaded"
if (xmlhttp.status==200)
{// 200 = "OK"
myvar=1; //remove this line, not necessary
alert("It worked, here's the contents:" + xmlhttp.responseText);
}
else if (xmlhttp.status==404)
{
alert("Dang! no workee:" + xmlhttp.responseText);
}
else
{
alert("Som uther problemo:" + xmlhttp.responseText);
}
}
}
Jun 27 '08 #5
On May 15, 7:53 am, joe <m...@invalid.comwrote:
TMN <nash....@gmail.comwrote:
Hi All
If I want to use an xml file to hold some config parameters for a web
page do I need to load it with JS
or is there a way of including it in the <head?
Thanks
Tim

Here a sample how to load a page with Javascript.
Be adivsed that it returns immediately. So if you use it to intialize variables
do them in "whatever" function.

Here' what I mean (pseudocode):

line 0: ..
line 1: blah, blah;
line 2: loadXMLDoc(..); //loads a value to "myvar"
line 3: if (myvar==1)
line 4: blah, blah;
line 5: ...

When execution of code reaches Line 4 you'd expect "myvar" to have some value.
Not so! Caveat! "whatever" is executed (see below example code) when it's good
and ready. loadXMLDoc(..) returns immediately (well almost).

loadXMLDoc("http://www.yourhomepage.com/somefile.txt");

function loadXMLDoc(url)
{
xmlhttp=null;
if (window.XMLHttpRequest)
{// code for IE7, Firefox, Opera, etc.
xmlhttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlhttp!=null)
{
xmlhttp.onreadystatechange=whatever;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
else
{
alert("Your browser does not support it.");
}

}

function whatever()
{
if (xmlhttp.readyState==4)
{// 4 = "loaded"
if (xmlhttp.status==200)
{// 200 = "OK"
myvar=1; //remove this line, not necessary
alert("It worked, here's the contents:" + xmlhttp.responseText);
}
else if (xmlhttp.status==404)
{
alert("Dang! no workee:" + xmlhttp.responseText);
}
else
{
alert("Som uther problemo:" + xmlhttp.responseText);
}
}

}
Thanks to all who responded.

Tim
South Africa
Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2699
by: Joe | last post by:
Hi Does anyone know of any issues about loading config files for windows forms applications? I have an application that utilizes a config file that holds my database connection string as well...
1
4334
by: Chris | last post by:
I have seen the posts on various places on the internet about .NET framework mismatch issues and I don't think that is my problem. ; ) When I execute the following C++.NET code: String...
0
1156
by: Jeff | last post by:
Hello, I've run into a problem with my asp.net application and would like to know whether the error is likely with my remote host. The problem is an unhandled exception, and the exception...
2
1793
by: Jeff | last post by:
Hello, I've run into a problem with my asp.net application and would like to know whether the error is likely with my remote host. The problem is an unhandled exception, and the exception...
13
1826
by: Duron | last post by:
I created a new folder using VS.NET 2003. Then I created a new web form under that folder, say, \Member\Default.aspx. However, even if I didn't do anything to that page, a run-time error appears...
2
1265
by: Patrick Olurotimi Ige | last post by:
Is it possible to execute a query or do some validation before loading a page.. I have a survey page and i want to validate users before loading the page. I have done it in the page_load. But...
7
10936
by: R Reyes | last post by:
Can someone please explain to me why I can't get the MS Word Interop assembly to work in my VS2005 project? I'm trying to manipulate MS Word from my Web Form application and I can't get passed...
5
12848
by: greenflame | last post by:
hello all, I have installed apache and php following the instructions on this link which was very helpful: http://www.tanguay.at/installPhp5.php5 problem: OS: Windows XP
0
1691
by: AndySummers | last post by:
Hi We have just re-written a majour asp.net project to use a user control embedded in a web page. The main dll references 3 other custom controls and so to deploy the project I copy the 4 dll's to...
3
12033
by: Mike | last post by:
Hi I have problem as folow: Caught Exception: System.Configuration.ConfigurationErrorsException: An error occurred loading a configuration file: Request for the permission of type...
0
7055
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6920
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7059
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6758
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7010
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5362
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3011
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1311
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
572
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.