Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Re: Fetch & Read XML Data into HTML File? >Thread Next - Re: Fetch & Read XML Data into HTML File? Re: Fetch & Read XML Data into HTML File?To: NULL Date: 9/9/2008 11:13:00 AM
"Martin Honnen" <mahotrash@y...> wrote in message
news:uW%23OnhmEJHA.1460@T......
> Richard In Va. wrote:
>
>> So your suggesting I do this...
>>
>> <html>
>> <title></title>
>> <head></head>
>> <body>
>>
>> <script language="JavaScript">
>
> I would put (all) the code to load and parse the XML into a function and
> call that function in the onload handler e.g.
> function loadXml (url)
> {
> var doc = ...;
> ...
> }
> window.onload = function () {
> loadXml('http://xoap.weather.com/weather/local/23218?cc=&dayf=7');
> };
>
>> var doc = new ActiveXObject('Msxml2.DOMDocument.3.0');
>> doc.async = false;
>> if
>> (doc.load('http://xoap.weather.com/weather/local/23218?cc=&dayf=7'))
>>
>> {
>> doc.setProperty('SelectionLanguage', 'XPath');
>> var locEl = doc.selectSingleNode('/wheather/loc');
> ^^^^^^^^^
> The word and element name is spelled 'weather' not 'wheater'. Sorry that I
> misspelled that in my earlier post.
>
>
>
>> As you can see, I'm probably completely lost, but I wonder if DOM
>> scripting would make things more simple for me.
>
> I think the problem is just the misspelled element name, other than that
> you are doing fine. Only if you have data for seven days of the week then
> you need to make sure you have seven rows in your table and different ids
> for those elements.
>
>> And with HTA, I loose the browser toolbar and tabed browsing that I would
>> have with a HTML file.
>
> If you want to use the browser IE and not a HTA then you need to check
> whether you can put the site you want to use into the trusted sites zone
> of IE and enable the access across domains for that zone.
>
> --
>
> Martin Honnen --- MVP XML
> http://JavaScript.FAQTs.com/
Martin, so your suggesting these edits...
------------------------
<html>
<title></title>
<head></head>
<body>
<script language="JavaScript">
function loadXml (url)
{
var doc = new ActiveXObject('Msxml2.DOMDocument.3.0');
doc.async = false;
}
window.onload = function ()
{
loadXml('http://xoap.weather.com/weather/local/23218?cc=&dayf=7');
};
{
doc.setProperty('SelectionLanguage', 'XPath');
var locEl = doc.selectSingleNode('/weather/loc');
var dnamEl = loc.selectSingleNode('dnam');
var dnam = dnamEl.text;
var tmEl = loc.selectSingleNode('tm');
var tm = tmEl.text;
}
var dayElements = doc.selectNodes('/weather/dayf/day');
for (var i = 0, l = dayElements.length; i < l; i++)
{
var dayElement = dayElements[i];
var dayName = dayElement.getAttribute('t'); // e.g. 'Monday'
var hiEl = dayElement.selectSingleNode('hi');
var hi = hiEl.text;
}
else
{
//deal with doc.parseError here
}
</script>
<table>
<tr>
<td><span id="dnam"></span></td> <!-- location of observation -->
<td><span id="tm"></span></td> <!-- time of observation -->
</tr>
</table>
<!-- misc html content here -->
<!-- Display Day 0 -->
<table>
<tr>
<td><span id="dayName"></span></td> <!-- day of week -->
<td><span id="t"></span></td> <!-- condition e.g. mostly sunny -->
<td><span id="hi"></span></td> <!-- day #0 forecast high temp -->
</tr>
</table>
<!-- misc html content here -->
<!-- Display Day 1 -->
<table>
<tr>
<td><span id="dayName"></span></td> <!-- day of week -->
<td><span id="t"></span></td> <!-- condition e.g. mostly sunny -->
<td><span id="hi"></span></td> <!-- day 1 forecast high -->
</tr>
</table>
<!-- Continue Tables for Days #2-6 (7 total days) -->
<!-- misc html content here -->
</body>
</html>
<!-- save file as HTA -->
-----------------------------------
Martin, is this more closer to what your talking about? I'm still confused
but maybe rightfully so, this is somewhat new to me.
Haven't quite figured out what the results of the loop will be, I suppose
the loop will yield "day name" and "hi temp" till it runs out of days?
CoffeeCup HTML editor shows the URL as "remarked out" due to the double //
as with...
loadXml('http://xoap.weather.com/weather/local/23218?cc=&dayf=7')
I can't get the code to execute, keep getting script errors when I open the
HTA file.
Also, I wonder if there is a way to do this with a list index (or something)
and assign a variable name to each item in the index. Every parent/child
element text content gets added to the index. The index could start with 1
and end up where ever it does. (just thinking out loud here)
Thanks once again Martin!
Richard in VA.
++++++++++++++++++++
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
