troubleshooting Question

How to read an XML document for import with PHP?

Avatar of Mulith
Mulith asked on
2 Comments1 Solution367 ViewsLast Modified:
I am trying to put together an script that imports listings to my site base on an XML document sent by my client. Initially I'm trying to just read the document and echo the different attributes of each record onto the screen before builder the script around that. The problem is I'm a little clueless about XML and not quite sure how to get my script to interperate correctly.

Here is what I have so far:


$xml = simplexml_load_file("JCG.xml");

echo $xml->getName() . "<br />";

foreach($xml->children() as $child)
  echo $child->getName() . ": " . $child . "<br />";

The problem with this is that there is one parent node(<PROPERTYDATA>) that wraps the entire document and then a child node for each record(<RECORD>). So all I get is <RECORD> printed to my screen instead of the attributes inside each record.

Here is a snippet from the XML doc:

<?xml version = "1.0" encoding="Windows-1252" standalone="yes"?>
		<IDOffice>Client - Stamford</IDOffice>
		<IDOffice>Client - Stamford</IDOffice>

Basically I want to create a loop that reads each of the attributes inside the record into a PHP variable and then adds that record to my database.

Any help would be appreciated. Thank you
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
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 2 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