Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Dziury po usunięciu wpisów w pliku XML
shpaque
post
Post #1





Grupa: Zarejestrowani
Postów: 651
Pomógł: 3
Dołączył: 31.01.2011
Skąd: Warszawa

Ostrzeżenie: (10%)
X----


Witam serdecznie,
obecny mój problem, to dziury pozostawione po usunięciu elementów w xml (zostają tabulatory lub spacje po istniałych gałęziach)

skrypt usuwający:

  1. $elementToRemove = 'catalog';
  2. $xmlFileToLoad = $xmlPath;
  3. $xmlFileToSave = $xmlPath;
  4.  
  5. $dom = new DOMDocument('1.0', 'utf-8');
  6. $dom -> load($xmlFileToLoad);
  7.  
  8. $matchingElements = $dom -> getElementsByTagName($elementToRemove);
  9. $totalMatches = $matchingElements -> length;
  10.  
  11. $elementsToDelete = array();
  12. for ($i = 0; $i < $totalMatches; $i++)
  13. {
  14. $elementsToDelete[$getFolderRow] = $matchingElements -> item($i);
  15. }
  16.  
  17. foreach ($elementsToDelete as $elementToDelete)
  18. {
  19. $elementToDelete -> parentNode -> removeChild($elementToDelete);
  20. }
  21. $dom -> save($xmlFileToSave);
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 25.08.2025 - 14:41