Jump to content

PHP XML HELP


tqla

Recommended Posts

I am working with an XML file that is formatted like this:

 

<pictures>
<pix pic="image1.png" alt="Tooltip Text 1" desc="Content 1" />
<pix pic="image2.png" alt="Tooltip Text 2" desc="Content 2" />
</pictures>

 

I need to load the file and make it into an array so that I can get the "pic", "alt" and "desc" information so that I can echo them.

 

I try this but it prints nothing:

 

$xml = simplexml_load_file('file.xml');
print_r($xml);

 

This prints nothing too:

 

$data = file_get_contents('file.xml');
print_r($data);

 

I figure it's because of the format of the xml file but I cannot change that.

 

All help appreciated.

Link to comment
Share on other sites

It seems to be something about the way the xml is formatted.

 

Your suggestions work great with this:

 

<catalog>
   <book id="bk101">
      <author>Gambardella, Matthew</author>
      <title>XML Developer's Guide</title>
   </book>
   <book id="bk102">
      <author>Ralls, Kim</author>
      <title>Midnight Rain</title>
   </book>
</catalog>

 

But I cannot get a result with this:

 

<pictures>
<pix pic="image1.png" alt="Tooltip Text 1" desc="Content 1" />
<pix pic="image2.png" alt="Tooltip Text 2" desc="Content 2" />
</pictures>

 

More help appreciated. Thanks.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.