开发者

Use an exsits array to delete xml content and return back to xml file.?

$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
    开发者_StackOverflow中文版                  [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>


Read the manuals.

$xml->asXML();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜