gpt4 book ai didi

c - 在 C 中编码 HTML 字符

转载 作者:太空宇宙 更新时间:2023-11-04 03:34:27 25 4
gpt4 key购买 nike

我正在通过套接字读取数据并使用 LibXML 对其进行解析。

我目前遇到的问题是,有时数据中的 Web 链接会破坏解析器。

http://example.com/?key=value&key2=value

有没有办法把它转换成html字符?

类似上面的东西

http://example.com/?key=value&key2=value

套接字数据示例:

<node link="http://example.com/?key=value&key2=value" />

编辑: Found a solution that works for my problem here

最佳答案

您必须在此处进行预过滤。与其他迹象相反,搜索和替换不会削减它。考虑您的搜索方是 &,它匹配太多。

构造如下有限状态机:

NORMAL:
if next matches "<" then TAG

TAG:
if next matches "![CDATA[" then CDATA
TAGSCAN

TAGSCAN:
if next matches whitespace then TAGSCAN2
if next matches > or next matches /> then NORMAL

TAGSCAN2:
if next matches whitespace then TAGSCAN2
if next matches SRC= or next matches HREF= then URL
TAGSCAN

URL:
we found an attribute with a URL in it. Do your search and replace
on the contents of the URL attribute value, advance past the URL and
go back to TAGSCAN

CDATA:
if next doesn't match ]]> then CDATA
NORMAL

关于c - 在 C 中编码 HTML 字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33713112/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com