
return result;
}
function escapeXML(string)
{
var result = “”,
i,
c;
for(i = 0;i < string.length;i++)
{
c = string.charAt(i);
if(c == ‘<’)
result += “<”;
else if(c == ‘&’)
result += “&”;
else
result += c;
}
return result;
}
// declares product object
function Product(id,name,price,description)
{
this.id = id;
this.name = name;
this.price = price;
this.description = description;
this.toXML = product_toXML;
}
function product_toXML()
{
var attrs = “id=’” + this.id + “‘“,
result = element(“name”,””,escapeXML(this.name));
result += element(“price”,””,escapeXML(this.price));
449
Viewer and Editor
continues