解析CDATA时出现问题

发布于 2024-11-03 18:05:46 字数 362 浏览 2 评论 0原文

   <text><![CDATA[øCu·l es tu principal reto, objetivo o problema?]]></text>

在解析上面的标签时,它崩溃了。 如何解析 CDATA

同一行出现在像这样的窗口中...

<text><![CDATA[¿Cuál es tu principal reto, objetivo o problema?]]></text>

由于特殊字符,解析器崩溃了。

为什么它们在 Mac 中被转换为特殊字符..? 怎么解决这个问题?

   <text><![CDATA[øCu·l es tu principal reto, objetivo o problema?]]></text>

while parsing the above tag, its crashing.
how to parse the CDATA

the same line is appearing in windows like this...

<text><![CDATA[¿Cuál es tu principal reto, objetivo o problema?]]></text>

due to the special chars the parser is crashing.

why they are converted into special chars in Mac..?
how to solve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

太阳公公是暖光 2024-11-10 18:05:46

其一,您在此处发布的字符串看起来编码出现了问题。 “ø”不是西班牙语字符。

您使用什么 xml 解析器?我猜想该字符串中的某处是一个字符,可能是隐藏的,或者可能是“ø”,这会使您的解析器崩溃。

编辑(回应OP的评论)

我会尝试猜测正在发生的事情,并希望您可以使用我的猜测来解决实际发生的情况。因此,当您创建 xml 文件时,您使用了一些编辑器。该编辑器使用了特定的编码。这意味着它使用从字符到字节的特定映射(它将字符编码为字节)将屏幕上的字符传输到磁盘上的字节。有许多不同的编码,一种常见的编码称为 Latin-1。因此,我们假设该文件是使用 Latin-1 编码的。创建文件后,您将文件传输到另一台计算机上,并在不同的编辑器中打开它。现在,新编辑器如何知道文件的编码?答案是它可能试图猜测编码。现在问题就出现了:它猜错了,并使用除 Latin-1 之外的编码来解释字节。

当您在编辑器中打开(乱码)文件时,请尝试从菜单中选择不同的编码。正确显示所有特殊字符的字符很可能是创建文件时使用的字符。

编辑2
但我的另一个问题仍然是:您使用什么 xml 解析器?

编辑3

好的,那么现在当您写“崩溃”时,您实际上是指崩溃还是只是返回?您收到错误消息吗?如果是的话,什么?您可以执行以下操作:

从该行中删除有趣的字符并在以下位置运行您的代码:

<text><![CDATA[l es tu principal reto, objetivo o problema?]]></text>

它仍然崩溃吗?

Well for one, the string as you post it here looks like something has gone wrong with the encoding. "ø" is not a Spanish character.

What xml parser are you using? I would guess that somewhere in that string is a character, possibly hidden, or maybe it's "ø" which makes your parser crash.

Edit (in response to the OP's comment)

I will try to guess what is happening and hope you can use my guess to resolve what is actually happening. So when you created the xml file you used some editor. This editor used a particular encoding. This means that it transferred the characters on your screen into bytes on your disk using a particular mapping from character into bytes (it encoded the characters into bytes). There are many different encodings, one common encoding is called Latin-1. So let's assume the file was encoded using Latin-1. After creating it, you transferred the file onto another machine where you opened it in a different editor. Now, how does the new editor know the encoding of the file? The answer is that it probably tried to guess the encoding. Now here is where the problem arises: it guessed wrong and interpreted the bytes using an encoding other than Latin-1.

While you have your (garbled) file open in an editor try selecting different encodings from the menu. The one that displays all your special characters correctly is likely to be the one used when the file was created.

Edit 2
But my other question remains: what xml parser are you using?

Edit 3

Ok, so now when you write "crashing", do you actually mean crashing or does it just return? Do you get an error message? If yes, what? Can you do the following:

Remove the funny characters from this line and run your code on the following:

<text><![CDATA[l es tu principal reto, objetivo o problema?]]></text>

Does it still crash?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文