- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要使用 Javascript 清除该文本 block 的部分内容:
<![CDATA[<a href="http://example.com/20.0.0.1/13902/cf085cef63511989576657751aad3cda.jpg" width="3543" height="2362" />Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. ]]>
更准确地说:
<![CDATA[<a href="http://example.com/20.0.0.1/13902/cf085cef63511989576657751aad3cda.jpg" width="3543" height="2362" />
还有这个:
]]>
请注意,第一部分并不总是相同的(来自 XML 源)。
最佳答案
由于您想要提取 CDATA 标记之间的文本,我建议您使用简单的正则表达式来完成这项工作。
function removeCDATA(str) {
var pattern = new RegExp(/\<!\[CDATA\[.*?\/>(.*?)\]\]\>/);
var res = pattern.exec(str)[1];
return res;
}
alert(removeCDATA('<![CDATA[<a href="http://example.com/20.0.0.1/13902/cf085cef63511989576657751aad3cda.jpg" width="3543" height="2362" />Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. ]]>'))
jsfiddle:link
关于javascript - 从字符串中清除 CDATA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23634491/
这个问题在这里已经有了答案: What does in XML mean? (13 个答案) 关闭 8 年前。 我不熟悉 XML 及其相关技术。 这个 CDATA 标签总是在开头,然后是一些东西
我遇到了这种困难的情况,我需要在另一个 CDATA 标签中使用 CDATA 标签。不过,这种情况很容易解释。 我有以下东西: ]]> 出于显示目的,我也需要将我的 Javascript 包装
我是 Blogger 博客用户。我曾经看到一个在 CDATA 标记内定位脚本的模板,如下所示: /**/ 虽然,我之前看到过类似的代码,如下所示: // 唯一不同的是/*
我很确定节可以在 XHTML5 中使用,但是 HTML5 呢? 最佳答案 CDATA structure 根本不是针对 HTML 的,它是针对 XML 的。 人们有时会在 XHTML 里面使用它们 s
我正在尝试删除字符串中的所有 [.*],但不删除 ![CDATA[xxx]]。我期待以下结果 """![CDATA[please remove[macro]]]""" .replaceAll(
不允许在 内堵塞。这是可以理解的。 现在,我必须在 中传输用户输入的数据堵塞。恶意用户可能会输入 或两者兼而有之。 问题是:处理这种情况的首选方法是什么? 剥离 ? 用空格替换它? 用错误消息打
我有一个定义元素“密码”的 XSD。我想允许任何角色存在。目前,我将元素定义为 xs:string用户必须转义字符串(例如 myP&ssword )或将其包含在 CDATA 标记中(例如 )
我在解析 XML 时遇到以下异常 org.xml.sax.SAXParseException: The processing instruction target matching "[xX][mM]
我正在尝试使用 powershell 读取 rss 提要,但无法在提要中提取 cdata 部分 这是提要的片段(为了节省空间,剪掉了一些项目): ... text 2011-11-28T
XML文档中的所有文本均会被解析器解析 只有CDATA 区段中的文本会被解析器忽略 PCDATA - 被解析的字符数据 XML解析器通常会解析 XML 文档中所有的文本 当某个XML 元素被解
我需要使用 Javascript 清除该文本 block 的部分内容: Lorem Ipsum is simply dummy text of the printing and typesetting
我看到了 solution让 XmlSerializer 输出 CDATA 部分,但是是否可以根据另一个值有条件地实现这一点? 下面的代码演示了我想要的结果: enum LogItemType {
我正在 Angular 应用程序中进行 soap 调用。 我需要为其中一个调用的有效载荷部分传递 CDDATA angular.forEach(contactsCollection, function
请帮帮我 在终端中: C no longer supported in regex; marked by / 我的文件 perl 中的代码 if ($html =~ //) 解决这个问题的最佳方法是什
我得到一个包含 CDATA 的字符串,我想删除它。 Input : "" Output I want : Hello World 我想获取 之间的所有数据和 并将其添加到
最近,我正在创建一个模块来将谷歌再营销标签添加到网上商店。根据文档,我已经为不同类型的页面(产品、类别、购物车等)准备了 google_tag_params。一切顺利,直到客户使用 Chrome 的
我试图在描述字段中创建 CDATA 部分,但失败了。代码非常简单,但在生成的 XML 中没有出现 CDATA 部分!! Node de = document.createElement("descri
这个问题是由开发人员 Michael Rys 相当激进地拒绝将 CDATA 部分的解析包含到 FOR XML PATH 中引起的,因为 "There is no semantic difference
您好,我这里有一个 CDATA 示例 和 我的 CDATA 正则表达式无法识别这个 "])*"]]>" 这也行不通 "][^\]]*[\]]{2,})*">" 有人可以给我一个 的正则表达式吗?
我经常使用内联 Javascript,通常是在我制作的 WordPress 主题中。我没有听说过在 // 中包装内联 Javascript直到几个月前,几年来我一直在以相当的能力水平做这件事。 我四处
我是一名优秀的程序员,十分优秀!