Jump to content

Associative Array to XML Function


nathanblogs

Recommended Posts

Hello,

 

Does any know an associative array to XML function?

 

At the moment I'm creating a associative array from a xml file, for example

<root>
<name>test</name>
<age>20</age>
<city>perth</city>
</root>

would turn into

array(1) {
  ["ROOT"]=>
  array(1) {
    [0]=>
    array(3) {
      ["NAME"]=>
      array(1) {
        [0]=>
        array(1) {
          ["VALUE"]=>
          string(4) "test"
        }
      }
      ["AGE"]=>
      array(1) {
        [0]=>
        array(1) {
          ["VALUE"]=>
          string(2) "20"
        }
      }
      ["CITY"]=>
      array(1) {
        [0]=>
        array(1) {
          ["VALUE"]=>
          string(5) "perth"
        }
      }
    }
  }
}

Link to comment
https://forums.phpfreaks.com/topic/75724-associative-array-to-xml-function/
Share on other sites

Thanks, but they don't work the same way :(. I have moved on and I am now trying to achieve what I was doing with simpleXML instead of using arrays.

 

basically I'm trying to modify an xml file based on the parent nodes it has for example I might have something like this

 

<root>
<nav>
<ref>name1</ref>
<parent>name2</parent>
<item>a heap of irrelevant information</item>
</nav>
<nav>
<ref>name2</ref>
<parent></parent>
<item>a heap of irrelevant information</item>
</nav>
</root>

would be modified to
<root>
<nav>
<ref>name2</ref>
<parent></parent>
<item>
<nav>
<ref>name1</ref>
<parent>name2</parent>
<item>a heap of irrelevant information</item>
</nav>
</item>
<item>a heap of irrelevant information</item>
</nav>
</root>

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.