# XML Parse Into Array

**URL:** <https://forum.kirupa.com/t/xml-parse-into-array/191165>\
**Category:** Uncategorized\
**Created:** [June 18, 2006, 1:44am UTC](https://forum.kirupa.com/t/xml-parse-into-array/191165 "2006-06-18T01:44:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Templarian](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/templarian/32/7152_2.png) [@Templarian](https://forum.kirupa.com/u/Templarian)\
**Post date:** [June 18, 2006, 1:44am UTC](https://forum.kirupa.com/t/xml-parse-into-array/191165/1 "2006-06-18T01:44:41Z")

</div>

Starters I’m developing for V4.0 and up so no simple\_XML. Just skip down to see what i want to do. I’ve tried for the last 3 hours and cant figure it out.

//edit, is it possible to get the source for simple\_xml and just include it with the file or is that against the licence/use thingy’s.

```php

//Parse Function//
function parse_node($node) {
    global $PART;
    if ($node->has_child_nodes()) {
        foreach($node->child_nodes() as $n) {
            if ($n->node_name() == '#text') {
                eval("$node->name=\"" . $n->node_value() . "\";");
            }
            else {
                $n->name = $node->name . '->' . $n->node_name();
                parse_node($n);
            }
        }
    }
}
//Read File//
$xmlstg = file_get_contents("xtag.xml");
$xmlstg = str_replace("
", "", $xmlstg);
$xmlstg = str_replace("	", "", $xmlstg);

//Parse File//    
$dom = domxml_open_mem($xmlstg,DOMXML_LOAD_PARSING,$error);
$root = $dom->document_element();
$root->name = '$PART';
parse_node($root);

//Get Part//
$value = $PART->parts->part1;

```

```auto

<?xml version="1.0"?>
<PART>
 <parts>
  <part1>valueiget</part1>
  <part2>othervalue</part2>
 </parts>
</PART>

```

\*\* What I want to do with the XML and PHP.\*\*

```php

//Get Part//
$value = $PART->parts[1]->part1;

```

```auto

<?xml version="1.0"?>
<PART>
 <parts>
  <part1>othervalue</part1>
  <part2>othervalue</part2>
 </parts>
 <parts>
  <part1>valueiget</part1>
  <part2>othervalue</part2>
 </parts>
</PART>

```
