Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [XML][PHP]PHP do XML, znacznik image z "href"
Forum PHP.pl > Forum > Przedszkole
Delleg
Najpierw kod

  1. $xml=new Domdocument("1.0" );
  2. $xml->encoding="UTF-8";
  3. $xml->formatOutput=true;
  4. $coffins=$xml->createElement("coffins");
  5. $xml->appendChild($coffins);
  6.  
  7. $size = $row['size'];
  8. $coffin=$xml->createElement("coffin");
  9. //$coffin->setAttribute("image", $winpath);
  10. $coffin->setAttribute("Kategorie", $cat);
  11. $coffins->appendChild($coffin);
  12. $name=$xml->createElement("name",$name);
  13. $coffin->appendChild($name);
  14. $image=$xml->createElement("PSD", $winpath );
  15. //$coffin->appendChild($image);
  16. $xcat=$xml->createElement("category",$cat);
  17. $coffin->appendChild($xcat);
  18. $xtype=$xml->createElement("type",$type);
  19. $coffin->appendChild($xtype);
  20. $xverb=$xml->createElement("veneered",$verb);
  21. $coffin->appendChild($xverb);
  22. $xsize=$xml->createElement("Überbreite",$size);
  23. $coffin->appendChild($xsize);


powyższy kod tworzy plik XML (podaję tylko wycinek)

  1. <coffin Kategorie="Kiefer">
  2. <name>No. 29 Kiefer Eiche furniert mit Palme Ornament</name>
  3. <image>href="file:///coffins/coffin_id_1.psd"</image>
  4. <category>Kiefer</category>
  5. <type>Furniert</type>
  6. <veneered>Eiche</veneered>
  7. <Size>2000x700x640</Size>
  8. </coffin>


Problem w tym że zamiast <image>href="file:///coffins/coffin_id_1.psd"</image> powinno być <image href="file:///coffins/coffin_id_1.psd"/>, jak to wykonać?
KsaR
  1. $image = $xml->createElement('image');
  2. $href = $xml->createAttribute('href');
  3. $href->value = 'file:///coffins/coffin_id_1.psd';
  4. $image->appendChild($href);
  5. $coffin->appendChild($image);

Delleg
Cytat(KsaR @ 8.11.2016, 06:56:59 ) *
  1. $image = $xml->createElement('image');
  2. $href = $xml->createAttribute('href');
  3. $href->value = 'file:///coffins/coffin_id_1.psd';
  4. $image->appendChild($href);
  5. $coffin->appendChild($image);

Rzeczywiście banalnie proste, dziękuje Ci bardzo za pomoc. W moim przypadku wartość value to winpath
efekt końcowy to:

  1. <coffin Kategorie="Kiefer">
  2. <name>No. 29 Kiefer Eiche furniert mit Palme Ornament</name>
  3. <image href="href="file:///trumny/coffin_id_1.psd"/>
  4. <category>Kiefer</category>
  5. <type>Furniert</type>
  6. <veneered>Eiche</veneered>
  7. <Size>2000x700x640</Size>
  8. </coffin>
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.