XML 解析错误:格式不正确

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10051969/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 13:26:28  来源:igfitidea点击:

XML Parsing Error: not well-formed

xml

提问by user838037

I am creating a sitemap XML from my database it's about videos sitemap. In XML, I am fetching the video title as titleand description as description, but there are some titles and descriptions written in Thai, Portuguese, German, and other languages. While generating the XML through PHP I am facing a problem that says:

我正在从我的数据库中创建一个站点地图 XML,它是关于视频站点地图的。在 XML 中,我将视频标题title和描述提取为description,但有一些标题和描述是用泰语、葡萄牙语、德语和其他语言编写的。通过 PHP 生成 XML 时,我遇到了一个问题:

"XML Parsing Error: not well-formed".

“XML 解析错误:格式不正确”。

Generation of the XML stops after encountering this error.

遇到此错误后,将停止生成 XML。

XML Parsing Error: not well-formed
Location: http://localhost/mydesk/sitemap.php
Line Number 24489, Column 69:

I observed it contained invalid characters like listed below, and I have replaced all types of these characters, but I realized there are other characters being used in other languages.

我观察到它包含如下所列的无效字符,我已经替换了这些字符的所有类型,但我意识到在其他语言中还使用了其他字符。

D ? ′ ? ? à ? D ‰ ? ù ° § ? ? ? ± … ? 3 è ? ? | ? ? ? a ? ? ? ? μ ? ? D ? 1 ? 2 D ? ? ? D μ ] : ? < * ? > % a ? # " ' ? ? ? ? ? ? ? ? o ? ¥ ? ? ¤ ? ? ? ? ¢ ¨ ˉ £

? ' ? ? 一种 ?D ‰ ? ù ° § ? ? ? ±……?3 ? ? | ? ? ? 一种 ?? ? ? μ ? ? ? 1 ? 二维?? ? Dμ]:?< * ? > % ? #"' ? ? ? ? ? ? ? o ? ¥ ? ? ¤ ? ? ? ¢ ¨ ˉ £

Is there any way to handle this issue that supports all languages?

有没有办法处理这个支持所有语言的问题?

回答by FDisk

If you get this error message try view the page source by pressing Ctrl+UUsually there is a "symbol in wrong place. And check your html syntax.

如果您收到此错误消息,请尝试按Ctrl+查看页面源代码U通常"在错误的位置有一个符号。并检查您的 html 语法。

回答by mister270

Can you open your xml document in a hex editor? If so see if it takes 1 byte per character or 2. If it takes 2 bytes per character you should try UTF-16 for encoding instead. If you do keep in mind that the only encoding you can guarantee a parser will support is UTF-8. Should support UTF-16 too but not all do.

您可以在十六进制编辑器中打开您的 xml 文档吗?如果是这样,看看是每个字符需要 1 个字节还是 2 个。如果每个字符需要 2 个字节,您应该尝试使用 UTF-16 进行编码。如果您确实记住,您可以保证解析器支持的唯一编码是 UTF-8。也应该支持 UTF-16,但并非全部支持。