Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8891257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:41:39+00:00 2026-06-14T22:41:39+00:00

I am trying to save data from my xml file into the mysql database

  • 0

I am trying to save data from my xml file into the mysql database using codeigniter & php. But I couldn’t find a way to escape special xml characters to save my data from the xml file to my table, 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); 

But I am getting this error:

Error:

simplexml_load_string(): Entity: line 37: parser error : Unescaped ‘<‘ not allowed in attributes values.

customer.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>

How can I avoid this error and avoid special xml characters so that my code save all the records from the xml file into the database?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:41:40+00:00Added an answer on June 14, 2026 at 10:41 pm

    You will want to review the htmlentities to encode and html_entity_decode to restore them back. Using the htmlentities will allow you to not have to worry about replacing each of the special characters like the ampersand individually and it will replace the arrows as well. I believe the escape_str will take care of the quotes for you.

    The documentation found in the links below should assist you with any unanswered questions.

    http://php.net/manual/en/function.htmlentities.php

    http://www.php.net/manual/en/function.html-entity-decode.php

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to save some data into a xml file using the following PHP
Hello there im trying to save some data from dynamic textboxes into XML file.
I am trying to extract data from XML file and save it my C#
I'm trying to save the returned data from HTTP request into a variable. The
I am trying to save data into the same table several times from the
I am trying to create & save images from data in an email from
I'm trying to save some data into an array but unfortunately all the data
I'm trying to save some data to A file in android, I'm using herefor
I'm trying to use Nokogiri to grab some data from an XML file, then
I'm doing an iPhone app that reads data from XML file, turn them into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.