如何逃脱或替换“&"使用jQuery的xml文件中? [英] How to escape or replace "&" in xml file using jQuery?

查看:27
本文介绍了如何逃脱或替换“&"使用jQuery的xml文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个xml文件,该文件可能会包含5个特殊字符,例如&"我知道xml在解析这些字符时会抛出错误.我使用jQuery ajax方法从xml文件中获取数据.是否有办法克服javascript中的解析器错误,例如替换特殊字符?

I have got a xml file that might get the 5 special characters like "&" inserted during a process.I know xml will throw error while parsing these characters.Im using the jQuery ajax method to get the data from the xml file.Is there any way of overcoming this parser error in javascript like replacing the special characters?

推荐答案

简而言之,是的,假设您以字符串形式获取xml(如果我没记错的话,jQuery就是这样).然后,您可以执行以下操作:

In short, yes, assuming you get your xml as a string (which if I recall correctly, jQuery does). Then you can do the following:

xmlstr = xmlstr.replace(/&/g, "&");

要替换的任何字符.

这篇关于如何逃脱或替换“&"使用jQuery的xml文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆