This is very easy i'm sure but as usual being totally thick and i'm new to SimpleXML.

All I want to do is add and or edit particular notes based on a given value. example xml file: 

```
<site>
    <page>
     <pagename>index</pagename>
      <title>PHP: Behind the Parser</title>
      <id>abc
      <plot>
       So, this language. It's like, a programming language. Or is it a
       scripting language? All is revealed in this thrilling horror spoof
       of a documentary.
      </plot>
      </id>
      <id>def
      <plot>
      2345234 So, this language. It's like, a programming language. Or is it a
       scripting language? All is revealed in this thrilling horror spoof
       of a documentary.
      </plot>
      </id>
    </page>

     <page>
      <pagename>testit</pagename>
      <title>node2</title>
      <id>345
      <plot>
       345234 So, this language. It's like, a programming language. Or is it a
       scripting language? All is revealed in this thrilling horror spoof
       of a documentary.
      </plot>
      </id>
    </page>
    </site>

```

If I want to add an and to index how do I find the node key

I can add the content e.g.

```
$itemsNode = $site->page->pagename;

$itemsNode->addChild("id", '12121')->addChild('plot', 'John Doe');

```

but what I want/need to do is add content to pagename='index' or pagename='testit' I cannot see a way to get that (in example) index is key[0] and testit is key[1] without doing some form of foreach loop with a switch etc. There must be an easy way to do it? no? 

so it should look something like this me thinks (but does not work otherwise would not bas asking question)

```
$paget = 'index' //(or testit')
if( (string) $site->page->pagename == $paget ){

$itemsNode = $site->page;

$itemsNode->addChild("id", '12121')->addChild('plot', 'John Doe');

}

```