How to construct a document from a string
I have got a string, which is html-like ,I want to extract the element in the html text, I know that I can use htmlparser with java, but how to do the same function with javascript?
How can I construct a document from the string, Does createHTMLDocument work?
Or any other way to extract the element in the html text?
for example:
I have got the html text as :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"               "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />   
<title>titleValue</title> 
<meta name="description" content="It is a good way to learn science." /> 
<meta name="keywords" content="Symfony2,Redis,PHP" /> 
<meta name="author" content="CSDN.NET" /> 
<meta name="Copyright" content="CSDN.NET" /> 
</head> 
<body> 
.......................... 
</body> 
</html>
how to get the value of "description"
Here is my code, but the output is 0, what's wrong?
                                var el = document.createElement("div");
                                el.innerHTML = ' <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>titleValue</title> <meta name="description" content="It is a good way to learn science." /> <meta name="keywords" content="Symfony2,Redis,PHP" /> <meta name="author" content="CSDN.NET" /> <meta name="Copyright" content="CSDN.NET" /> </head> <body> hello</body> </html>';
                                var descElements = el.getElementsByTagName("head");
                                document.getElementById("news_content").innerHTML = descElements.length;
 
    