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/8/2008 6:56:00 PM
Richard In Va. wrote:
> Okay, I think I can follow that, but how do I single out the individual days
> when...
>
> <dayf>
> <day d="0" t="Monday" dt="Sep 8">
> <hi>90</hi>
> <low>70</low>
> <part p="d">
> <t>Mostly Sunny</t>
> <ppcp>20</ppcp>
> <hmid>66</hmid>
>
> I'll want the "Monday", <hi>, <low>, <t>, <ppcp> and <hmid> for each day
> #0-6
> If you can show me how to get the "Monday" and 1 element within day #0 I'll
> figure the rest.
You would access a node list of 'day' elements with
var dayElements = doc.selectNodes('/weather/dayf/day');
then you can loop through that list
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;
}
As for inserting data you get from the XML document into your HTML
document, you can do that by either preparing the HTML with elements to
take the data e.g. you would put a span
<span id="dnam"></span>
into your HTML document where you want to display that data, then you
could access that as
var dnamSpan = document.getElementById('dnam');
dnamSpan.innerText = dnam;
where dnma is the variable in my earlier post.
For the data of the days of the week you would probably use a HTML table
and populate that.
Or alternatively you could use DOM scripting to create all those HTML
dynamically.
XSLT is also a nice tool to transform XML to HTML, not sure if you would
want to try that.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
