troubleshooting Question

parsing xml having similar tags but different values

Avatar of srikanth saladi
srikanth saladi asked on
PHPXML
8 Comments1 Solution348 ViewsLast Modified:
Hi

I am facing a problem with xml parsing.My xml is like this

<textlist><textitem>
<text>
disc 1
</text>
<type>
disc_title
</type>
</textitem>
<textitem>
<text>
cd
</text>
<type>
cd_title
</type>
</textitem>
<textitem>
<text>
disk asdf
</text>
<type>
disc_text
</type>
</textitem>
<textitem>
<text>
cd has ddf
</text>
<type>
cd_text
</type>
</textitem>
<textitem>
<text>
disc_img.png
</text>
<type>
disc_image
</type>
</textitem>
</textlist>

To fetch the disc related  data i have stored types in db in a table in three columns(item_title(disc_title),item_text(disc_text),item_image(disc_image)) .While parsing I want to fetching the types from db and comparing them with xml (<type>) types and read corresponding  <text> values.But the problem is the tags are not in sequence.for disc title ,text,image are not in sequence.How is it possible to read the disc info and store in an array for further processing.

eg.I want the data like item_array['title'],item_array['text'],item_array['image'].I have tried like this
$info = $xml->{'textlist'}->{'textitem'};

foreach(info  as  $item_details)
{
   if(in_array( $item_details->{'type'},$dbtablearray['item_title']))
{
$title = $item_details->{'text'};
}
 if(in_array( $item_details->{'type'},$dbtablearray['item_text']))
{
$text = $item_details->{'text'};
}
}
$item_array =array('title'=>$title ........) like this
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros