Ben zorluk NodeList tek bir düğüm değerini ayıklanması yaşıyorum.
Benim kod, çeşitli alanların bazı içeren metin, dosya yolları ve uzantıları ile tam görüntü adlarını tutan bir xml dosyası alır.
Ben belli bir kimliği ile düğüm madde arıyorsanız, bunun üzerinde bir expath sorgusu çalıştırın. Daha sonra eşleşen düğüm öğeyi saklar ve $ oldnode olarak kaydeder
Şimdi benim sorunum $ oldnode bir değer elde etmek için çalışıyor. "Nesne (DOMElement) # 8 (0) {}:" Ben ($ oldnode) var_dump ve print_r ($ oldnode) denedim ama aşağıdaki döndürür
$ Oldnode değişkeni tahmin Im bir nesne, ama onu nasıl ulaşabilirim?
Ben kullanarak bütün düğüm listesini echo taşıyor: echo $ oldnode-> nodeValue;
Bu liste tüm düğümleri gösterir.
İşte xml dosyasını işleme kodudur. hattı 6 söz hattı ...
$xpathexp = "//item[@id=". $updateID ."]";
$xpath = new DOMXpath($xml);
$nodelist = $xpath->query($xpathexp);
if((is_null($nodelist)) || (! is_numeric($nodelist))) {
$oldnode = $nodelist->item(0);
echo $oldnode->nodeValue;
//$imgUpload = strchr($oldnode->nodeValue, ' ');
//$imgUpload = strrchr($imgUpload, '/');
//explode('/',$imgUpload);
//$imgUpload = trim($imgUpload);
$newItem = new DomDocument;
$item_node = $newItem ->createElement('item');
//Create attribute on the node as well
$item_node ->setAttribute("id", $updateID);
$largeImageText = $newItem->createElement('largeImgText');
$largeImageText->appendChild( $newItem->createCDATASection($largeImgText));
$item_node->appendChild($largeImageText);
$urlANode = $newItem->createElement('urlA');
$urlANode->appendChild( $newItem->createCDATASection($urlA));
$item_node->appendChild($urlANode);
$largeImg = $newItem->createElement('largeImg');
$largeImg->appendChild( $newItem->createCDATASection($imgUpload));
$item_node->appendChild($largeImg);
$thumbnailTextNode = $newItem->createElement('thumbnailText');
$thumbnailTextNode->appendChild( $newItem->createCDATASection($thumbnailText));
$item_node->appendChild($thumbnailTextNode);
$urlB = $newItem->createElement('urlB');
$urlB->appendChild( $newItem->createCDATASection($urlA));
$item_node->appendChild($urlB);
$thumbnailImg = $newItem->createElement('thumbnailImg');
$thumbnailImg->appendChild( $newItem->createCDATASection(basename($_FILES['thumbnailImg']['name'])));
$item_node->appendChild($thumbnailImg);
$newItem->appendChild($item_node);
$newnode = $xml->importNode($newItem->documentElement, true);
// Replace
$oldnode->parentNode->replaceChild($newnode, $oldnode);
// Display
$xml->save($xmlFileData);
//header('Location: index.php?a=112&id=5');
Herhangi bir yardım büyük olurdu.
Teşekkürler