1

我被困住了,试图弄清楚为 .php 放置什么代码我的问题是 xml 文件的数组应该是什么,尤其是“href 链接”</p>

       $xml = new DOMDocument ("1.0","UTF-8");

       $playlists = $xml -> createElement("playlists");
       $playlists = $xml -> appendChild($playlists);

       $playlist = $xml ->  createElement ("playlist"); 
       $playlist = $playlists -> appendChild ($playlist);

       $track = $xml ->  createElement ("track");
       $track = $playlist -> appendChild ($track);

       $meta = $xml ->  createElement ("meta"); 
       $meta = $track -> appendChild ($meta);

       $xml->formatOutput = true;
       $string_value = $xml->saveXML();
       $xml->save("preview.xml");

XML 代码:

<playlists>
    <playlist id="pl1">
        <track href="music/adg3com_bustedchump.mp3" title="Artist 1 - Track 1"     target="http://google.de" rel="covers/cover1.jpg">
            <meta>
                <![CDATA[ <a href="http://google.de" target="_blank">This is an optional text with a link</a> ]]>
            </meta>
        </track>
        <track href="music/adg3com_chuckedknuckles.mp3" title="Artist 2 - Track 2" target="" rel="">
            <meta><![CDATA[This is an optional text]]></meta>
        </track>
    </playlist>
    <playlist id="pl2">
        <track href="http://soundcloud.com/djlewisvi/afrojack-lionheart" title="Afrojack - Lionheart" />
        <track href="music/adg3com_chuckedknuckles.mp3" title="Artist 3 - Track 3" target="" rel="covers/cover1.jpg">
            <meta><![CDATA[This is an optional text]]></meta>
        </track>
        <track href="http://soundcloud.com/radykal/favorites" title="Soundcloud Favorites" />
    </playlist>
</playlists>
4

1 回答 1

0

不知道我是否有你的问题。如果不合适,请让我知道并完善您的问题!
这是在节点中创建href属性的方法:<track>

$track = $xml ->  createElement ("track");
$href = $xml->createAttribute('href');
$href->value="http://soundcloud.com/djlewisvi/afrojack-lionheart";
$track->appendChild($href);
$track = $playlist -> appendChild ($track);

看到它工作:http ://codepad.viper-7.com/uC9J2Y

于 2013-05-05T21:14:12.557 回答