AllisonC
AllisonC

Reputation: 3099

Why am I getting an undefined error with my xml?

I was trying to follow the answer from here: Create XML in Javascript

I am getting an error in the console "undefined is not a function" for the 2nd line here:

var mat = document.createElement("mat");
imgsource = mat.createAttribute("imgsrc");
imgsource.nodeValue = default_matte_source;

total_size = mat.createAttribute("total_size");
total_size.nodeValue = 7.5;

cpu = mat.createAttribute("cpu");
cpu.nodeValue = 12;

cid = mat.createAttribute("cid");
cid.nodeValue = default_matte_cid;

Upvotes: 0

Views: 78

Answers (1)

Paul Roub
Paul Roub

Reputation: 36438

createAttribute() is a method of document, not of individual nodes. You'll want something like:

imgsource = document.createAttribute('imgsrc');
imgsource.nodeValue = default_matte_source;
mat.setAttributeNode(imgsource);

Upvotes: 2

Related Questions