我有一个带有 Javascript 的 HTML 文件。但我无法使用 tinyXML2 库加载此 HTML 文件。它给出了错误。
我的 html 文件是这样的abc.html
:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>HTML Course</title>
<style type="text/css">
ul.LinkedList { display: block; }
/* ul.LinkedList ul { display: none; } */
.HandCursorStyle { cursor: pointer; cursor: hand; } /* For IE */
</style>
<script type="text/JavaScript">
function addEvents() {
activateTree(document.getElementById("LinkedList1"));
}
function activateTree()
{
for(var i=0; i < oList.getElementsByTagName("ul").length; i++)
{
oList.getElementsByTagName("ul")[i].style.display="none";
}
if(oList.addEventListener)
{
oList.addEventListener("click", toggleBranch, false);
}
else if(oList.attachEvent)
{
oList.attachEvent("onclick", toggleBranch);
}
addLinksToBranches(oList);
}
</script>
</head>
<body >
<ul id="LinkedList1" class="LinkedList">
<li>History of WWW
<ul>
<li>Arpanet - Packets - 1969</li>
<li>TCP/IP - Vinton Cerf - 1974</li>
<li>WorldWideWeb (Internet and program) - Tim Berners Lee - 1991</li>
<li>Public Domain WWW source code - 1993</li>
<li>NCSA Mosaic released - 1993</li>
<li>Opera released - 1994</li>
<li>Marc Anderseen (formerly NCSA) and Jim Clark release Netscape - 1994</li>
<li>IE from Microsoft (based on Mosaic)
<ul>
<li>DHTML</li>
<li>ActiveX</li>
</ul>
</li>
<li>W3C at MIT (CERN, NCSA, EU)</li>
<li>W3C Recommendations</li>
<li>Mozilla Foundation</li>
</ul>
</li>
</ul>
</body>
</html>
我加载这个 html 文件的 c++ 代码是:
tinyxml2::XMLDocument xmlDoc;
tinyxml2::XMLError err = xmlDoc.LoadFile("abc.html");
现在err
有错误代码XML_ERROR_PARSING_ELEMENT
。
我想要做的这个 HTML 文件是在标签<ul>
下找到一个特定的标签<body>
,并希望在该标签内添加更多项目。
请让我知道它为什么会出错以及我该如何以某种方式做到这一点。