简体   繁体   中英

XML error message Opening and ending tag mismatch

<?xml version="1.0" encoding="utf-8"?>

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ramy Capital</title> />
</head>

Error message is below. What am I doing wrong?

Opening and ending tag mismatch: meta line 0 and head

从倒数第二行删除“/>”

The problem is that you try to handle HTML as XML. An HTML-parser is more fault-tolerant, because an XML-file has to be well-formed (and as a stricter condition, be valid , that means adhering to a certain Schema(XSD or other)). Such an XML document has to satisfy the following conditions :

The syntax rules were described in the previous chapters:

  • XML documents must have a root element
  • XML elements must have a closing tag
  • XML tags are case sensitive
  • XML elements must be properly nested
  • XML attribute values must be quoted

So, a well-formed version of your code would be

<?xml version="1.0" encoding="utf-8"?>
<head>
  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Ramy Capital</title>
</head>

This is XML, and not HTML.

You're trying to parse HTML as XML which won't work. HTML is based on/uses features from SGML not supported by XML (ie. not part of the XML subset of SGML). Specifically, your markup contains meta start-element tags without subsequent end-element tags. To use elements in this way in SGML, you'd have to declare such elements as having EMPTY content (or alternatively, declare the element to allow end-tag omission). HTML parsers have these rules hard-coded or can resolve/load suitable markup declarations.

If you want to continue using XML for your task at hand, you must edit your input markup as advised by zx485 or equivalent. Alternatively, you could use an HTML or SGML parser. For using SGML to convert any valid HTML with all bells and whistles to XML/XHTML, you can follow a tutorial I prepared two years ago: Parsing HTML on sgmljs.net ; you'll also find extensive info about other common HTML parsing issues linked from there.

And in any case, also do as advised by Rahul Maurya and remove the bogus end-element-tag-like character sequence you inserted in an attempt to fix your markup.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM