how to retrieve particular node.. i.e., if b node had value like <b id="1"> means it will return b's child nodes..
output must be:

Here is my code:

$string = <<<XML
<b id="1">
$xml = new SimpleXMLElement($string);
   // echo "<c>".(string)$child."</c>";
    foreach( $xml->children() AS $child )
    //run any query you want on the children.. they are also nodes.
   $name1 = $child;
  //echo "<pre><c></pre>".$name1."<pre><c></pre><br>";
   foreach( $name1->children() AS $child1 )
     $name2 = $child1->getName();
    // echo $name2."--".$child2;
        //foreach($child1->query('//b[@name="title"]') as $child2)

        echo "<".$name2.">".$child2."<⁄".$name2.">"."<br>";

Member Avatar

From the manual:

You could try something like this...

function getChildXML($xml, $tag, $id)
    $output = '';
    $doc = new DOMDocument();
    $xpath = new DOMXpath($doc);
    $elements = $xpath->query($tag . "[@id='$id']");
    foreach($elements as $element)
        $output .= $doc->saveXML($element);
    return $output;

print getChildXML($string, 'b', 1);

Which gives the output...

<b id="1">

Obviously you could develop the function to deal with 'no id' values etc.

For me it display's something like this.
text stuff..
But i need <c>text</c>

thank you so much.. got it.. but don want <b id="1"> jus wanna display child nodes..