Jump to content

Generate XML list


mikey3521

Recommended Posts

Hey Everyone, I have a directory with a few photos in it.

Image1_img

Image2_img

etc. I have a php script that generates thumbnails for these to match so

Image1_tmb

Image2_tmb ...

 

now what I need is a script to generate an xml file which will look like this:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<content>
  <gallery>
    <image Thumb="image1_tmb" Large="image1_img"></image>
    <image Thumb="image2_tmb" Large="image2_img"></image>
    <image Thumb="image3_tmb" Large="image3_img"></image>
</gallery>
</content>

 

any thoughts would be greatly appreciated! = )

Link to comment
https://forums.phpfreaks.com/topic/169998-generate-xml-list/
Share on other sites

Probably using DOMDocument ( http://us3.php.net/manual/en/class.domdocument.php ) or simpleXML ( http://us2.php.net/simplexml ). Haven't used simplexml so can't help with it. But using DOMDocument you could do something like this.. not sure tho if you can anyhow give the standalone parameter for the xml tag.

<?php
$doc = new DOMDocument('1.0', 'UTF-8');
$doc->formatOutput = true;

$content = $doc->createElement('content');
$doc->appendChild($content);

$gallery = $doc->createElement('gallery');

$img1 = $doc->createElement('image');
$img1->setAttribute('Thumb', 'image1_tmb');
$img1->setAttribute('Large', 'image1_img');
$gallery->appendChild($img1);

$img2 = $doc->createElement('image');
$img2->setAttribute('Thumb', 'image2_tmb');
$img2->setAttribute('Large', 'image2_img');
$gallery->appendChild($img2);

$img3 = $doc->createElement('image');
$img3->setAttribute('Thumb', 'image3_tmb');
$img3->setAttribute('Large', 'image3_img');
$gallery->appendChild($img3);

$content->appendChild($gallery);
echo $doc->save('test.xml');

 

Of course you should modify this code to work more dynamically like adding the images in loop etc. but this is just a simple example.

Link to comment
https://forums.phpfreaks.com/topic/169998-generate-xml-list/#findComment-896837
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.