Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    Modificare DomDocument via Xpath

    La mia richiesta è semplice: mi servirebbe sapere come aggiungere un nodo, ad un elemento del DomDocument dopo aver fatto una query xpath:
    Codice PHP:
    public function append($string$path '//html/body') {
        
    $xpath = new DOMXPath $this->response );
        
    $elements $xpath->evaluate $path$this->response );
        for(
    $i 0$i $elements->length$i ++) {
            if (! 
    $string instanceof DOMNode) {
                
    $string $this->response->createDocumentFragment ()->appendXML $string );
            }
            
    $elements->item $i )->appendChild $this->response->importNode $stringtrue ) );
        }

    quando vado a recuperare l'elemento $this->response, non trovo il nuovo elemento che sarebbe dovuto essere appeso.
    Spero sia stato chiaro

  2. #2
    risolto
    Codice PHP:
    public function append($string$path '//html/body') {
            
    $xpath = new DOMXPath $this->response );
            
    $elements $xpath->evaluate $path$this->response );
            foreach ( 
    $elements as $element ) {
                if (! 
    $string instanceof DOMNode) {
                    
    $string_ $string;
                    
    $string $this->response->createDocumentFragment ();
                    
    $string->appendXML $string_ );
                }
                
    $element->appendChild $this->response->importNode $stringtrue ) );
            }
        } 

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.