troubleshooting Question

PHP: Parsing XML file

Avatar of trevor1940
trevor1940 asked on
PHPXML
8 Comments1 Solution153 ViewsLast Modified:
Hi
I'm attempting to pass an XML file

    $xml = simplexml_load_file('test.xml');
 
   var_dump($xml);

Produces

\\Path\To\test.php
object(SimpleXMLElement)[1]
  public 'title' => string "My Title" (length=8)
 ........
public  'properties ' =>
           array (size=1234)
                  0=>
                    object(SimpleXMLElement)[2]
                  2=>
                    object(SimpleXMLElement)[2]
                  3=>
                    object(SimpleXMLElement)[4]

Before some one asks I cannot upload the xml file but it looks like this (There might be errors due to fat fingers)

<?xml version="1.0" encoding="UTF-8" ?>
<resultset  xmlns="http://example.com/" xmlns:ns2="http://example.com/path/to/file" xmlns:ns2="http://example.com/path/to/other/file">
  <title>The Searchers</title>
  <date>1956</date>
  <properties >
    <ns2:name>overview</ns2:name>
    <ns2:value  xmlns:xs="http://www.w3.org/2001/XMLSchema"  xsi:type="xs:string">As a Civil War veteran spends years searching for a young niece captured by Indians, his motivation becomes increasingly questionable.</ns2:value>
  </properties >
  <properties >
    <ns2:name>Director</ns2:name>
    <ns2:value  xmlns:xs="http://www.w3.org/2001/XMLSchema"  xsi:type="xs:string">John Ford</ns2:value>
  </properties >
  <properties >
    <ns2:name>actors</ns2:name>
    <ns2:value xmlns:xsi="http://example.com/XMLSchema" xsi:type="ns2:list">
       <ns2:entries xmlns:xs="http://www.w3.org/2001/XMLSchema"  xsi:type="xs:string">John Wayne</ns2:entries>
       <ns2:entries xmlns:xs="http://www.w3.org/2001/XMLSchema"  xsi:type="xs:string">Jeffrey Hunter</ns2:entries>
       <ns2:entries xmlns:xs="http://www.w3.org/2001/XMLSchema"  xsi:type="xs:string">Vera Miles</ns2:entries>
       <ns2:entries xmlns:xs="http://www.w3.org/2001/XMLSchema"  xsi:type="xs:string">Natalie Wood</ns2:entries>
</ns2:value>
  </properties >
 <filmData>
    <location>Monument Valley</location>
     <imdb>https://www.imdb.com/title/tt0049730/</imdb>
 <filmData>
</resultset>';

Could someone suggest how to get the value of  title and how to loop through the "Properties Array"  accessing the elements of   object(SimpleXMLElement)[2] (In the XML these are Name Value pears that don't show up in the var_dump also the parts of filmData?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 8 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 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