[FX.php List] [Off] XML help

Steve Winter steve at matatirosolutions.co.uk
Thu Feb 28 10:05:05 MST 2008


Hi,

 

What I want to be able to do (the why I want to do this is long, and
irrelevant ;-) is to read data from an XML file, preferably into an array,
work with that data, display some, change some, generally muck with it, then
convert the array back into an XML string and save it back out as an XML
file.

 

I've looked at lots of array2xml and xml2array classes on the net, but none
of them seem to be able to seamlessly perform this task. generally they seem
to end up mangling things when trying to go from the array back to the XML.

 

As an example, if I use this xml;

 

<?xml version="1.0" encoding="iso-8859-1"?>

<users>

  <user>

            <name>John Doe</name>

            <address>Binary Avenue 1234 FL</address>

            <email>john at john-domain.com</email>

  </user>

  <user>

            <name>Janet Smith</name>

            <address>Crazy Bits Road 4568 CA</address>

            <email>janet at janet-domain.com</email>

  </user>

</users>

 

Then most of the xml2array parsers will deliver me this;

 

Array
(
    [users] => Array
        (
            [user] => Array
                (
                    [0] => Array
                        (
                            [name] => John Doe
                            [address] => Binary Avenue 1234 FL
                            [email] => john at john-domain.com
                        )
 
                    [1] => Array
                        (
                            [name] => Janet Smith
                            [address] => Crazy Bits Road 4568 CA
                            [email] => janet at janet-domain.com
                        )

                                    )

                )

)

 

Which is all well and good, and looks handy and works well for the 'in' side
of things.

 

However when I try to go back to XML, I end up with dumb stuff, for example;

 

<users>

  <user>

    <use>

       <name>John Doe</name>

       <address>Binary Avenue 1234 FL</address>

        <email>john at john-domain.com</email>

    </use>

    <use>

        <name>Janet Smith</name>

        <address>Crazy Bits Road 4568 CA</address>

        <email>janet at janet-domain.com</email>

    </use>

  </user>

</users

 

Which of course, gives me a different array if I feed it back in again. the
problem seems to relate to the extra level of the array from the original
XML.

 

And sadly I can't seem to figure out how the various classes are recursing
the array well enough to fix it.!

 

Does anyone have an xml2array array2xml class that works that they'd be
willing to share with me.? 

 

Thanks

Steve

 

Steve Winter
Matatiro Solutions Limited
steve at matatirosolutions.co.uk 
p:  +44 23 8023 8809
m: +44 77 7852 4776

3 Calshot Court, Channel Way
Ocean Village, Southampton SO14 3GR

Registered in England and Wales: 6300320
Registered Office: 44 Southchurch Road, Southend, SS1 2LZ
VAT Registration Number: 916 8809 86
IMPORTANT: This message is private and confidential. If you have received
this message in error, please notify us and remove it from your system.

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.iviking.org/pipermail/fx.php_list/attachments/20080228/d605a5a6/attachment-0001.html


More information about the FX.php_List mailing list