473,394 Members | 1,845 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

XML & Javascript parser

Hi

In order to build a weather prediction page, I was thinking to write
down a Javascript (on the client). This javascript should contact a
server (www.live.com) in ordert to extract the weather forecast.

In summary, I want a javascript based on the html client (internet
Explorer), creating a connection and extractign the data.
This sounds simple but for whatever reason, I cannot manage to extract
any data of this XML page.

Perhaps can you help me?

This code you can past it, as a document by it s own and test it and
complete it for your own pages (the server is ready to answer you).

thanks
<script language="javascript">
<!--

// Server pages - Parameters.
// URL = <Debut>+CodeVille+<Fin>
var Debut =
"http://www.live.com/cfw/weatherdata.aspx?wealocations=fr:";
var Fin = "&weadegreetype=C&culture=fr-fr&rand=0.0";
// Objects initialisation
function Weather(code)
{
//Path
this.Code = code; //town code (key)
this.LocationName = null; // Full name of the town
this.URL = null; //path for icons
this.ImageRelativeURL = null; // second part of the path

//Weather of the current day
this.CurrentTemperature = null;
this.Skycode = null; //icon
this.SkyText = null; //description
this.Date = null; //date
this.Day = null; // day of the week
this.Time = null; // time
}

// LThis is the function which has the problem
Weather.prototype.GetData = function()
{
// Object creation
var xmlData = new ActiveXObject("Microsoft.XMLDOM");
xmlData.async=false;

// URL
var URL = Debut + this.Code + Fin;

// Check the URL
alert(URL);

// Connection to the XMLwebpage
xmlData.load(URL);

// Check the connection by displaying any data
alert(xmlData.documentElement.childNodes(1).text); // <---- Here
is the error. I tryed with and without 'documentElement', but this does
not work

//read data...
alert(xmlData.root.children.item("weatherdata"));
}
// Strasbourg is the town I want to have. initialisation of the Data
var Strasbourg = new Weather("FRm_Strasbourg");

// Strasbourg object receive the data.
Strasbourg.GetData();

-->
</script>

Feb 28 '06 #1
8 1591
ri******@gmail.com wrote:
In order to build a weather prediction page, I was thinking to write
down a Javascript (on the client). This javascript should contact a
server (www.live.com) in ordert to extract the weather forecast.


You can't access resources out of your domain name. So you'll need to
make a proxy.

"download.abc?uri=http://www.live.com"
--
Jonas Raoni Soares Silva
http://www.jsfromhell.com
Feb 28 '06 #2
That s strange, is it a security restriction of Internet Explorer ?

Feb 28 '06 #3
ri******@gmail.com wrote:
That s strange, is it a security restriction of Internet Explorer ?

Is what? Please quote what you are replying to.

I you are referring to the inability access resources out of your domain
name, its a standard security restriction.

--
Ian Collins.
Feb 28 '06 #4
ri******@gmail.com wrote:
That s strange, is it a security restriction of Internet Explorer ?


It is a restriction of all browsers. XMLHttpRequests can only be made to
the domain that served the page containing the request. There are
significant security issues in doing otherwise.

You can get around that with JSON and dynamically created script elements,
provided the server you want to connect to supports it.

<URL:http://borkweb.com/story/look-ma-cross-domain-scripting>
Look for weather servers that support JSON or JSONP.
--
Rob
Feb 28 '06 #5
RobG wrote:
ri******@gmail.com wrote:
That s strange, is it a security restriction of Internet Explorer ?
It is a restriction of all browsers. XMLHttpRequests can only be made to
the domain that served the page containing the request. There are
significant security issues in doing otherwise.


Specifically, if cross domain XMLHttpRequest was possible, and you
happened to visit a malicious site, what it could do is to simulate a
page submission sequence in your name. That is to say, from the point
of view of that remote domain, it is getting a request from the browser
so as far as it can tell, the browser's user is the one making the
request (Note: one off cross domain requests are available using
I/FRAMEs, but you can't get at them).

Csaba Gabor from Vienna
You can get around that with JSON and dynamically created script elements,
provided the server you want to connect to supports it.

<URL:http://borkweb.com/story/look-ma-cross-domain-scripting>


See also: http://www.json.org/
http://developer.yahoo.net/common/json.html

Mar 2 '06 #6
Thank you very much for your help, and your precious information!

Mar 6 '06 #7

ri******@gmail.com wrote:
Thank you very much for your help, and your precious information!


One other thought. If you are making this page just for yourself, and
you are working on the Windows platform, you can save the web page with
the extension ".hta" : I think it should then run the web page with
fewer security restrictions.

Regards

Julian Turner

Mar 6 '06 #8

ri******@gmail.com wrote:
In order to build a weather prediction page, I was thinking to write
down a Javascript (on the client). This javascript should contact a
server (www.live.com) in ordert to extract the weather forecast.
In summary, I want a javascript based on the html client (internet
Explorer), creating a connection and extractign the data.
This sounds simple but for whatever reason, I cannot manage to extract
any data of this XML page.
Perhaps can you help me?


Hello,

As someone mentioned already, using an AJAX-style callback would
probably work best for this kind of thing. I put together a really
simple AJAX example script, in case you need somewhere to start:

http://www.impliedbydesign.com/super...ming-seed.html

I hope that helps. Good luck!

Chris S.

Free Web Design Tools
http://www.impliedbydesign.com/free-...e-scripts.html

Mar 6 '06 #9

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

Similar topics

3
by: wenke | last post by:
Hi, I am using the following code (see below) from php.net (http://www.php.net/manual/en/ref.xml.php, example 1) to parse an XML file (encoded in UTF-8). I changed the code slightly so that the...
4
by: higabe | last post by:
Three questions 1) I have a string function that works perfectly but according to W3C.org web site is syntactically flawed because it contains the characters </ in sequence. So how am I...
2
by: Thierry Lam | last post by:
Let's say I have the following xml tag: <para role="source">a & b</para> Currently, an xml parser will treat & as a special character. Does anyone know the special characters to use around...
4
by: johkar | last post by:
When the output method is set to xml, even though I have CDATA around my JavaScript, the operaters of && and < are converted to XML character entities which causes errors in my JavaScript. I know...
7
by: Thomas | last post by:
Hi all! Currently I have a web application that consists of a classic frameset. I would like to rebuild the application and just use tables or layers. The problem is, that some parts of the...
14
by: madtom1999 | last post by:
I'm trying to put a non-breaking space ( or any other entity for that matter) into a node eg: node.nodeValue+='&nbsp'; however the actual code is written in the html -ie it displays as >&nbsp;<...
1
by: xmlnaive | last post by:
i'm a nebie to XML world and I have a weird scenario. If my element looks like this <name>first&amp;last<\name>, the output of the parser is "&last" instead of "first&last". I'm using xereces 2.5...
3
by: jinendrashankar | last post by:
i am getting following error in my code help me to slove this issue $ gcc -Wall -g -I/usr/include/libxml2/libxml -c create_xml.c In file included from create_xml.c:2:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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,...
0
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...

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.