Xml içeriği silmek ve xml dosyaya geri dönmek için bir exsits dizi kullanın.?

0 Cevap
$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
                  )

              )

          )

      )

VE $ A unsurları silmek hangi belirtmek için $ dizi kullanımı var.

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

Yani $ A kalır unsurları iade edilecektir:

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

                  )

              )
          )

  )

ve bu böyle olacak $ xml denklik:

  <?xml version='1.0'?> 
  <document>
        <books>    
            <book>
            <qty>21</qty>
            <title>PHP</title>
            </book>    
          </books>    
  </document>

0 Cevap