-1

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 行目: パーサー エラー: エスケープされていない '<' は属性値では許可されていません。

顧客.xml

<?xml version="1.0" standalone="yes"?>
<Rows>
<Row CustomerAccountNumber="12" Name="Arj" Desciption="PJ psm" />  
<Row CustomerAccountNumber="1" Name="Aj" Desciption="*/Artic" />
<Row CustomerAccountNumber="2" Name="smla" Desciption="& light" />
<Row CustomerAccountNumber="3" Name="alik" Desciption="*/Artic" />
<Row CustomerAccountNumber="4" Name="wqla" Desciption="" />
<Row CustomerAccountNumber="5" Name="walij" Desciption="16-17" />
<Row CustomerAccountNumber="6" Name="li" Desciption="sales@llil.com" />
</Rows>

コードがすべてのレコードを xml ファイルからデータベースに保存するように、このエラーを回避し、特殊な xml 文字を回避するにはどうすればよいですか?

4

3 に答える 3

0

ActiveRecord は、引用符を含む文字列のエスケープ処理を行い'ます"。したがって、明示的にmysql_real_escape_string()のようなものを使用する必要はありません。<他の XML 文字は問題なく、エスケープする必要はありません>

また、あなた (または他の誰か) は、XML 属性の「説明」のスペルを間違っています。

于 2012-11-26T17:14:03.173 に答える