Simple XML - Dealing With Colons In Nodes

前端 未结 4 505
悲&欢浪女
悲&欢浪女 2020-11-22 14:40

I\'m trying to read an RSS feed from Flickr but it has some nodes which are not readable by Simple XML (media:thumbnail, flickr:profile, and so on)

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-22 15:04

    An even simpler method using PHP of accessing namespaced XML nodes without declaring a namespace is....

    In order to get the value of > from the following source

    
      My important article
      Mon, 29 Feb 2017 00:00:00 +0000
      https://myxmlsource.com/32984
      https://myxmlsource.com/32984
      Blogs, Jo
      
        Human Affairs
      
      4f329b923419b3cb2c654d615e22588c
      hIwW14tLc+4l/oo7agmRrcjwe531u+mO/3IG3xe5jMg=
      /32984/Download/0032984-11042.docx
      Journal article
      Blogs, Jo
      0
    
    

    Use the following code:

    $rss = new DOMDocument();
    
    $rss->load('https://myxmlsource.com/rss/xml');
    
    $nodes = $rss->getElementsByTagName('item');
    
    foreach ($nodes as $node) {
        $title = $node->getElementsByTagName('title')->item(0)->nodeValue;
        $author = $node->getElementsByTagName('author')->item(0)->nodeValue;
        $authorHash = $node->getElementsByTagName('authorHash')->item(0)->nodeValue;
        $department = $node->getElementsByTagName('department')->item(0)->nodeValue;
        $email = decryptEmail($node->getElementsByTagName('authorEmail')->item(0)->nodeValue);
    }
    

提交回复
热议问题