خرید بک لینک

Vote count: 0

want to make loop and Parsing XML CDATA my XML

<?xml version="1.0"?>
<photos>
    <photo image="images/1.jpg" url="http://LINKHERE" target="_blank" id="1">
    </photo>
    <photo image="images/1.jpg" url="http://LINKHERE" target="_blank" id="2">
    </photo>
</photos>

my code

for ($x = 1; $x <= 10; $x++) {
    $dom=new DOMDocument();
    $xml='images.xml';
    $dom->load($xml);
    $xp = new DomXPath($dom);
    //$item_content = $xp->query("//*[@id = $x]");
    foreach ($dom->getElementsByTagName('photos') as $item) {
        $cdata=$dom->createCDATASection('<head>test'.$x.'</head><body></body>');
        $item->getElementsByTagName('photo')->item(0)->appendChild($cdata);
    }
    $dom->save($xml);
}

but the result

    <photo image="images/1.jpg" url="http://LINKHERE" target="_blank" id="1">
    <![CDATA[<head>test1</head><body></body><head>test2</head><body></body><head>test3</head><body></body>
    <head>test4</head><body></body><head>test5</head><body></body>
<head>test6</head><body></body><head>test7</head>
    <body></body><head>test8</head><body></body><head>test9</head><body></body>]]><![CDATA[<head>test10</head><body>
    </body>]]></photo>
    <photo image="images/2.jpg" url="http://http://LINKHERE" target="_blank" id="2">
    </photo>

i want it be this

<photo image="images/1.jpg" url="http://LINKHERE" target="_blank" id="1">
<![CDATA[<head>test1</head><body></body>]]></photo>
<photo image="images/2.jpg" url="http://http://LINKHERE" target="_blank" id="2">
<![CDATA[<head>test2</head><body></body>]]></photo>

i want move on loop by id i try many times but no way , i think i have a problem on my loop need some help here

asked 5 mins ago

برچسب: نویسنده: استخدام کار تاريخ: چهارشنبه 29 ارديبهشت 1395 ساعت: 20:01

صفحه بندی