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
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>

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.