Why does my DOMParser not parse the following fairly simple DOM structure?

var newDOM ="<div><strong>Error!</strong> Refresh, Please... </div>", parser = new DOMParser(), doc = parser.parseFromString(xmlString, "text/xml"); 

ReferenceError: xmlString is not defined

Closed due to the fact that off-topic participants Darth , Andrew Bystrov , 0xdb , AK , MSDN.WhiteKnight 21 Jun '18 at 9:16 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - Darth, Andrew Bystrov, 0xdb, AK, MSDN.WhiteKnight
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • 1) You have a variable called newDOM , not xmlString . Did you read the text of the error? 2) Not text/xml , but text/html - Darth

2 answers 2

The error says:

Error with link: xmlString variable not found.

When you call the parser.parseFromString function, you need to pass the newDOM variable to newDOM like this:

 var newDOM ="<div><strong>Error!</strong> Refresh, Please... </div>", parser = new DOMParser(), doc = parser.parseFromString(newDOM, "text/html"); 

And another newDOM : does not concern this error, but concerns an error in the future: Since your newDOM string is an HTML string, you need to write "text/html" , and not "text/xml" in the second parameter of the parser.parseFromString function.

    The error is all written. The DOM structure is in newDOM , and you are trying to xmlString .