admin管理员组文章数量:1336321
I am getting data from text box and change it into xml format and store it in data base. For allowing special characters i wrote javascript function to replace special character with its html entities.
" "
& &
< <
> >
for "quotes , less than , greater than" its working fine. for "&" it is showing xml parser error i used javascript to replace special character with its entity
string.replace(/</g, '<').replace(/>/g, '>').replace(/&/g, '&').replace(/"/g, '"').replace(/'/g, "\\'");
for "&" allow showing warning but it get stored in data base. please help me to sort out this problem .
i begin with string.replace(/&/g, '&') even though i am getting
Warning: SimpleXMLElement::__construct(): Entity: line 9: parser error : EntityRef: expecting ';' in /var/www/
i tried this also &amp; as mentioned in this link stackoverflow/questions/1328538/…
After that there is no warning but while saving in db it saved as "ab & cd"
I am getting data from text box and change it into xml format and store it in data base. For allowing special characters i wrote javascript function to replace special character with its html entities.
" "
& &
< <
> >
for "quotes , less than , greater than" its working fine. for "&" it is showing xml parser error i used javascript to replace special character with its entity
string.replace(/</g, '<').replace(/>/g, '>').replace(/&/g, '&').replace(/"/g, '"').replace(/'/g, "\\'");
for "&" allow showing warning but it get stored in data base. please help me to sort out this problem .
i begin with string.replace(/&/g, '&') even though i am getting
Warning: SimpleXMLElement::__construct(): Entity: line 9: parser error : EntityRef: expecting ';' in /var/www/
i tried this also &amp; as mentioned in this link stackoverflow./questions/1328538/…
After that there is no warning but while saving in db it saved as "ab & cd"
- 1 Once you write parse error, once warning - what's the case now? Can you post the error/warning-message please? – Christoph Commented Jul 19, 2012 at 7:37
- What database? Where is the JS running (browser? node? soething else?)? Is the JS talking directly to the database or do you have some server side program in between? – Quentin Commented Jul 19, 2012 at 8:09
1 Answer
Reset to default 6Start with replacing the &
character, then replace the other characters. Otherwise you will replace &
from the previous entities (<
etc.) by &
string.replace(/&/g, '&amp;') //<= start with
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g, '&apos');
// ' may be "\\'", depends on how te OP wants to use it
[edit based on ments] use &amp;
to replace the ampersand character
本文标签: javascripthow to parse xml with special character specifically for ampersandStack Overflow
版权声明:本文标题:javascript - how to parse xml with special character? specifically for ampersand - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742332604a2454992.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论