When doing this in console, why do I get a parse error?
TR = '<TR id=line1 class="myClass"><INPUT id=input1 type=hidden> <INPUT id=input2> <TD style="PADDING-LEFT: 20px" align=left> <IMG class=im border=0 src="images/img.gif"> Hello </TD><!-- comment --> <TD id=cell1 align=right></TD> <TD id=cell2 align=right></TD> <TD align=middle> </TD> <TD align=middle></TD></TR>';
parser = new DOMParser()
xmlDocument = _parser.parseFromString(TR, "text/xml");
You create a new
DOMParser()
and assign it to a variable namedparser
:But then you reference an undeclared variable
_parser
on the next line:If you replace
_parser
withparser
, the console error should go away.First problem (I assume it's not the one you're experiencing, rather that this code is erroneously copy-pasted): Your variable name is
parser
, not_parser
.Your main problem is that you're trying to parse HTML as XML, which will work IF your HTML is also valid XML. But yours isn't. Quote your attributes for a start. That's what
means.
After you do that, close your void elements. It's OK to leave off the trailing slash in HTML5, but not within the stricter rules of XML.