Unable to generate XML file with this big URL

前端 未结 1 1287
面向向阳花
面向向阳花 2021-01-29 10:06

I want to generate XML with this following code but it\'s giving error as I include big URL. Even cdata is not working:

$xml = new SimpleXMLElement(\'

        
相关标签:
1条回答
  • 2021-01-29 10:39

    You can not add CDATA sections with SimpleXML, only standard text nodes. But even that has a bug. The text can not contain entities (the &...;). The same bug exists in DOMDocument::createElement and DOMNode::$nodeValue. You can create the document with DOM however.

    $dom = new DOMDocument();
    $root = $dom->appendChild($dom->createElement('xml'));
    
    for ($i = 1; $i <= 8; ++$i) {
        $track = $root->appendChild($dom->createElement('track'));
        $track
          ->appendChild($dom->createElement('path'))
          ->appendChild($dom->createTextNode('data['));
        $track
          ->appendChild($dom->createElement('title'))
          ->appendChild($dom->createCDATASection("http://r8---sn-5hn7sn7k.googlevideo.com/videoplayback?mt=1417417897&mv=m&ms=au&ip=2001:1af8:4700:a022:1::4ae9&itag=18&initcwndbps=4948750&mm=31&sver=3&id=o-AB1_DFOem6qVMtWki7uWj0CcIevyqEaY_OtwcbRPKZXT&ipbits=0&upn=IFgTkloUxQQ&expire=1417439567&fexp=902522,907259,922247,927622,932404,935694,941004,942810,943909,947209,948124,952302,952605,952901,953912,957103,957105,957201&key=yt5&sparams=dur,id,initcwndbps,ip,ipbits,itag,mm,ms,mv,source,upn,expire&source=youtube&signature=7266EE8B52AAB9E3C6DECBADDD112BDF00E85EFB.362737C47ECAE4D9E25E900E8C24483799B2A8F8&dur=1554.831&title=8+Stunning+Linguistic+Miracles+of+The+Holy+Quran+%7C+Kinetic+Typography"));
    }
    
    $dom->formatOutput = TRUE;
    print($dom->saveXML());
    

    You can see that DOM document has a bunch of methods to create the different node types. The nodes have some methods to append the new node to them.

    The methods return the nodes so you can nest them.

    0 讨论(0)
提交回复
热议问题