Why is this xmlreader code not working?

后端 未结 3 1215
一个人的身影
一个人的身影 2021-01-07 05:05

I have a file that looks like this:

    
       About.com: Animation Guide         


        
3条回答
  •  無奈伤痛
    2021-01-07 05:30

    It'll take time and proper debugging to come up with working pure XMLReader code. Meanwhile try this hybrid method:

    $xmlR = new XMLReader;
    $xmlR->open('dbpedia/links/xml.xml');
    
    //Skip until  node
    while ($xmlR->read() && $xmlR->name !== 'ExternalPage');
    
    $loadedNS_f = false;
    while ($xmlR->name === 'ExternalPage')
    {
        //Read the entire parent tag with children
        $sxmlNode = new SimpleXMLElement($xmlR->readOuterXML());
    
        //collect all namespaces in node recursively once; assuming all nodes are similar
        if (!$loadedNS_f) {
            $tagNS = $sxmlNode->getNamespaces(true);
            $loadedNS_f = true; 
        }
        $URL = (string) $sxmlNode['about'];
        $dNS = $sxmlNode->children($tagNS['d']);
        $Title = (string) $dNS->Title;
        $Desc = (string) $dNS->Description;
        $Topic = (string)$sxmlNode->topic;
    
        var_dump($URL, $Title, $Desc, $Topic);
    
        // Jump to next  tag
        $xmlR->next('ExternalPage');
    }
    
    $xmlR->close();
    

提交回复
热议问题