Parsing XML to Fields

G’day.

I’ve been trying to populate fields on a form, when loaded on the Browser, from an XML file. I’ve written this code in the onload event of the form, but can’t get it to work. (My XML and Javascript knowledge is in it’s infancy.)

The form has 3 fields on it, all editable and available to web, named ‘to’, ‘from’ and ‘body’.

My test XML file I’m trying to load is in the following format:

<?xml version="1.0" encoding="ISO-8859-1" ?>

Subject: Parsing XML to Fields

function getmessage(){root = xmlDoc.documentElement;

to = root.getElementsByTagName(“to”)[0].childNodes[0].nodeValue;

from = root.getElementsByTagName(“from”)[0].childNodes[0].nodeValue;

message = root.getElementsByTagName(“body”)[0].childNodes[0].nodeValue;

f=document.forms[0];

f.to.value = to;

f.from.value = from;

f.message.value = message;

}

*look at DevGuru.com, to simplify your code further.

HTH

Adi