Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Dziury po usunięciu wpisów w pliku XML
shpaque
post 14.06.2018, 21:29:02
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
trueblue
post 14.06.2018, 21:43:08
Post #2





Grupa: Zarejestrowani
Postów: 6 761
Pomógł: 1822
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


  1. $dom->preserveWhiteSpace = false;
  2. $dom->formatOutput = true;
  3. $dom->save($xmlFileToSave);


--------------------
Go to the top of the page
+Quote Post
shpaque
post 15.06.2018, 09:50:38
Post #3





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

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


oczywiscie smile.gif to pomogło jednak tak jak piszą - wyłącznie wtedy kiedy jest bezpośrednio pod new DOMDocument

[nie pytaj o to samo w kilku postach bo robisz balagan. tresc usunieta]
Powód edycji: [nospor]:
Go to the top of the page
+Quote Post

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

 



RSS Wersja Lo-Fi Aktualny czas: 19.04.2024 - 11:32