在Codeigniter/php中转义xml字符

在Codeigniter/php中转义xml字符,php,mysql,xml,codeigniter,Php,Mysql,Xml,Codeigniter,我试图使用codeigniter和php将xml文件中的数据保存到mysql数据库中。但是我找不到一种方法来转义特殊的xml字符,以便将数据从xml文件保存到我的表cache_table中 Code: $xml_source = str_replace(array("&", "&"), array("&", "&"),file_get_contents('XML/customer.xml')); $xml = simplexml_load_

我试图使用codeigniter和php将xml文件中的数据保存到mysql数据库中。但是我找不到一种方法来转义特殊的xml字符,以便将数据从xml文件保存到我的表cache_table中

 Code:

 $xml_source = str_replace(array("&", "&"), array("&", "&"),file_get_contents('XML/customer.xml'));

$xml = simplexml_load_string($xml_source);  
foreach($xml as $row )
{
 $attr = $row->attributes();

$results[] = array('CustomerAccountNumber' => $this->db->escape_str($attr->CustomerAccountNumber),'Desciption' => $this->db->escape_str($attr->Desciption) ):

$this->db->insert_batch('cache_cust',$results); 
但我得到了这个错误:

错误:

simplexml_load_string():实体:第37行:解析器错误:Unescaped'错误说明了一切:

Unescaped '<' not allowed in attributes values.

ActiveRecord将负责转义包含引号字符的字符串,即
。因此,您不必显式使用类似的内容。其他XML字符也可以,不必转义,例如


你(或其他人)也会拼写“描述”“XML属性错误。

您需要查看要编码的html属性和要还原的html\u实体\u解码。使用htmlentities将使您不必担心单独替换每个特殊字符,如符号和,它也将替换箭头。我相信逃脱法庭会为你处理这些报价

下面链接中的文档可以帮助您解决任何未回答的问题


你能粘贴你的xml数据吗?@GBD我已经在问题中添加了xml数据。谢谢。在xml中有特殊含义的字符在SQL中不太可能有特殊含义。为什么你认为你需要逃避任何事情?@lvaroG.Vicario我的意思是我想屏蔽xml实体,以便将记录保存到数据库中。我是新的bie,我不知道如何在php/codeigniter中实现这一点。然后我有个好消息:你不必这么做。XML实体对数据库无害。
Unescaped '<' not allowed in attributes values.
$xml_source = str_replace(array("&amp;", "&"), array("&", "&amp;"),file_get_contents('XML/customer.xml'));