0

Good day all ! i have a multi-dimensional array. the array was carefully built from my xml structure. here's it :

array (size=1)
  'Articles' => 
    array (size=4)
      '@About' => string 'programming' (length=11)
      '@compile' => string 'pro' (length=3)
      'Article' => 
        array (size=3)
          0 => 
            array (size=6)
              ...
          1 => 
            array (size=6)
              ...
          2 => 
            array (size=6)
              ...
      '$' => string 'Idiot ! How to programme' (length=24)

where all attribute names are mapped against the '@' sign and node contents against the '$' sign. apparently, here's the xml data from where the above array was obtained :

<?xml version="1.0"?>

<Articles About="programming" compile="pro"> 

    Idiot ! How to programme

    <Article ID="111" Lang= "C++"> 
        Best Language
        <title HELP="Needed">C++ is my boss</title>
        <author>Idiotic Me</author> 
        <summary>if you dont like Cpp, your a Moron </summary> 
    </Article>

    <Article ID="222" Lang="Json">
     Or whatever it calls itself
        <title> Json is a fool
              <sub> just a test </sub>
        </title>
        <author> who cares !</author> 
        <summary> I detest json </summary> 
    </Article> 

    <Article ID="333" Lang="Ruby">
     Hottest in town
        <title> A rival of Cpp</title>
        <author> intersting to know</author> 
        <summary> a good language i think </summary>  
    </Article>    

</Articles>

i am finding it painful to convert the above array back into its exact xml form. any good analgesic to relieve me of this pain ?? thanks in advance !

Edited by osagie.odigie.148

2
Contributors
7
Replies
24
Views
2 Years
Discussion Span
Last Post by diafol
0

Please show the whole MD array as compared to the XML.
Is there a reason for the strings without surrounding tags in the XML? What purpose do they serve? Should they be there?

Edited by diafol

0
cant tell how to show it further than this. that was var_dump() but here's 
the return of print_r() :

Array ( 
        [Articles] => Array ( 
                      [@About] => programming 
                      [@compile] => pro 

         [Article] => Array 
                 ( 
                      [0] => Array 
                      ( 
                           [@ID] => 111 
                           [@Lang] => C++ 
                           [title] => Array ( 
                                 [@HELP] => Needed 
                           [$] => C++ is my boss 
                       ) 
                          [author] => Idiotic Me 
                          [summary] => if you dont like Cpp, your a Moron 
                          [$] => Best Language ) 
                       [1] => Array 
                       ( 
                          [@ID] => 222 
                          [@Lang] => Json 
                          [title] => 
                       Array 
                       ( 
                          [ox] => Array ( ) 
                          [$] => Json is a fool 
                       ) 
                          [author] => who cares ! 
                          [summary] => I detest json 
                          [$] => Or whatever it calls itself 
                        ) 

                        [2] => Array

                        ( 
                           [@ID] => 333 
                           [@Lang] => Ruby 
                           [title] => A rival of Cpp 
                           [author] => intersting to know 
                           [summary] => a good language i think 
                           [$] => Hottest in town 
                         ) 
                  ) 
                   [$] => Idiot ! How to programme 
                )
 ) 

as for the strigs without surrounding tags, i think its just my way of saying "this is the text content of this node"

0

I'd imagine that you need some sort of recursive function to dig into each array. Why do you need to do this? XML is a basic enough structure.

0

i needed a way to send xml as string to clients irrespective of the platform. for reasons of compactibility. such that client applications be it javascript or whatever will easily load it for parsing. please show me any link or idea if you have one

0

XML is a standard format created to work across platforms as it's just markup. I can't see that this is an improvement. I fear that you're looking for a solution where there's no problem. If you want a json<->xml convertor, there may be some out there, but the best way to create either is from source (usually a DB). Converting from one to the other can be tricky.

0

thanks diafol. the honest truth is, i am developing a robust appl that houses data in various formats. name it! DB, xml, json, excel, pdf, etc. i needed to simulate a cinerio were each of the objects can be interconverted. i realised that the easiest way out is to make them all implement a toarray() method. now am stocked, reinterpreting from array to my desired format, say json.

0

Robust will be a relative term I think. All those formats will have ways of tripping you up if they aren't formed exactly to your specification. Even Creating simple XL data from CSV can sometimes be troublesome. Building your own convertors is no mean feat. Good luck with it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.