0
$string = <<<XML
<?xml version='1.0'?> 
<document>
      <books>    
          <book>
              <qty>12</qty>
              <title>C++</title>
          </book>
          <book>
              <qty>21</qty>
              <title>PHP</title>
          </book>    
        </books>    
      <books>        
          <book>  
              <qty>21</qty>
              <title>PHP</title>
          </book>    
      </books>
</document>
XML;

$newsXML = new SimpleXMLElement($string);
$xml = simplexml_load_string($string);

print_r($xml);

 $A = SimpleXMLElement Object
      (
      [books] => Array
          (
          [0] => SimpleXMLElement Object
              (
              [book] => Array
                  (
                  [0] => SimpleXMLElement Object
                      (
                      [qty] => 12
                      [title] => C++
                      )

                  [1] => SimpleXMLElement Object
                      (
                      [qty] => 21
                      [title] => PHP
                      )

                  )

              )

          [1] => SimpleXMLElement Object
              (
              [book] => SimpleXMLElement Object
                  (
                  [qty] => 21
                  [title] => PHP
                  )

              )

          )

      )

AND Have an $arr use to indicate that which elements of $A will delete .

$arr = array(
           0=> array(0=>'12;C++'),
           1=> array(0=>'21;PHP')
      );

So $A will be return the remain elements :

$A = SimpleXMLElement Object
  (
      [books] => Array
          (
          [0] => SimpleXMLElement Object
              (
              [book] => Array
                  (
                  [0] => SimpleXMLElement Object
                      (
                      [qty] => 21
                      [title] => PHP
                      )

                  )

              )
          )

  )

and it equivalence to $xml will like this:

  <?xml version='1.0'?> 
  <document>
        <books>    
            <book>
            <qty>21</qty>
            <title>PHP</title>
            </book>    
          </books>    
  </document>
hakre
  • 193,403
  • 52
  • 435
  • 836
tree em
  • 20,379
  • 30
  • 92
  • 130
  • You cannot remove items using simplexml. read this post, as I believe it answers the same question. http://stackoverflow.com/questions/262351/remove-a-child-with-a-specific-attribute-in-simplexml-for-php – dqhendricks Dec 30 '10 at 17:40

1 Answers1

0

Read the manuals.

$xml->asXML();
Tatu Ulmanen
  • 123,288
  • 34
  • 187
  • 185