I've been instructing myself in XML DOM parsing using the w3schools
tutorial and decided to try an example of my own. I'd written a short
XML file that looked like this:
<?xml version="1.0" encoding="UTF-8"?>
<apartment>
<tenant>
<name>
<first>John</first>
<last>Smith</last>
</name>
<age>23</age>
<occupation>Stu dent</occupation>
</tenant>
<tenant>
<name>
<first>Alan</first>
<last>Smithee </last>
</name>
<age>22</age>
<occupation>Ser ver</occupation>
</tenant>
<tenant>
<name>
<first>Jane</first>
<last>Smith</last>
</name>
<age>34</age>
<occupation>Man ager</occupation>
</tenant>
</apartment>
I wanted to parse the xml dom with javascript and insert node values
into html elements at load calling the following function:
function parseXML()
{
xmlDoc = document.implem entation.create Document("","", null);
xmlDoc.async = "false";
xmlDoc.load("Ap artment.xml");
document.getEle mentById("fname ").innerHTM L =
xmlDoc.getEleme ntsByTagName("n ame")[0].childNodes[0].nodeValue;
}
When I tested to see the resulting output in Safari and Firefox, I
received to different error messages:
1) Safari 3.1's Inspector error console told me: value undefined Value
undefined (result of expression xmlDoc.load) is not object.
2) Firebug in Firefox told me: xmlDoc.getEleme ntsByTagName("n ame")[0]
has no properties
I decided to ignore Safari and focus on the Firefox bug first. I
deleted the last statement of the function just to make sure the xml
file was being loaded. However, no matter where I parsed the tree for
a node value, I was told the node had no value. So I decided to
validate my XML using the XML Developer extension for Firefox and ran
the XML through its validator (it used some default scheme when none
was provided) and I was told that:
cvc-elt.1: Cannot find the declaration of element 'apartment'.
Huh? But its right there! Am I doing something wrong?
tutorial and decided to try an example of my own. I'd written a short
XML file that looked like this:
<?xml version="1.0" encoding="UTF-8"?>
<apartment>
<tenant>
<name>
<first>John</first>
<last>Smith</last>
</name>
<age>23</age>
<occupation>Stu dent</occupation>
</tenant>
<tenant>
<name>
<first>Alan</first>
<last>Smithee </last>
</name>
<age>22</age>
<occupation>Ser ver</occupation>
</tenant>
<tenant>
<name>
<first>Jane</first>
<last>Smith</last>
</name>
<age>34</age>
<occupation>Man ager</occupation>
</tenant>
</apartment>
I wanted to parse the xml dom with javascript and insert node values
into html elements at load calling the following function:
function parseXML()
{
xmlDoc = document.implem entation.create Document("","", null);
xmlDoc.async = "false";
xmlDoc.load("Ap artment.xml");
document.getEle mentById("fname ").innerHTM L =
xmlDoc.getEleme ntsByTagName("n ame")[0].childNodes[0].nodeValue;
}
When I tested to see the resulting output in Safari and Firefox, I
received to different error messages:
1) Safari 3.1's Inspector error console told me: value undefined Value
undefined (result of expression xmlDoc.load) is not object.
2) Firebug in Firefox told me: xmlDoc.getEleme ntsByTagName("n ame")[0]
has no properties
I decided to ignore Safari and focus on the Firefox bug first. I
deleted the last statement of the function just to make sure the xml
file was being loaded. However, no matter where I parsed the tree for
a node value, I was told the node had no value. So I decided to
validate my XML using the XML Developer extension for Firefox and ran
the XML through its validator (it used some default scheme when none
was provided) and I was told that:
cvc-elt.1: Cannot find the declaration of element 'apartment'.
Huh? But its right there! Am I doing something wrong?
Comment