<articlelist> <article> <title>example title</title> <author>example author</author> <shortcontent>example content</shortcontent> <hascomments>example comments</hascomments> </article> </articlelist>
Jak napisać poprawne dtd do tego? Bo na razie mam coś takiego, ale XMLReader sypie mi warningami (co w sumie dziwne nie jest, bo wiem że robię błąd, tylko nie wiem jak go nie robić

<!DOCTYPE articlelist, article [ <!ELEMENT articlelist (article)> <!ELEMENT article (title,author,shortcontent,hascomments)> <!ELEMENT title (#PCDATA)> <!ELEMENT author (#PCDATA)> <!ELEMENT shortcontent (#PCDATA)> <!ELEMENT hascomments (#PCDATA)> ]>
I próbowałem kilku kombinacji, np. deklarowałem drugiego doctype poniżej ELEMENT articlelist, i w sumie jeszcze kilka innych rzeczy, ale dokument wciąż nie jest poprawny. Any suggestions?
Druga sprawa - to jest w zasadzie plik cache, który będzie trzymał to, co sami widzicie po nazwach elementów. Implementację odczytywania pliku w php chciałbym napisać tak, żeby nie była na sztywno - czyli jak przyjdzie inny programista i sobie powie, że np. element, który teraz nosi nazwę author, ma się nazywać authors i być rodzicem kilku innych elementów author (np. kiedy będzie kilku autorów

<?php while($dbObject -> read()) { $array[$dbObject -> name] = $dbObject -> value; } ?>
Wiadomo, nie ma problemu kiedy plik jest załóżmy taki jak wyżej. Wtedy tablica wygląda tak: $array['title']['tytuł'], ale co zrobić żeby w razie potrzeby odpowiedni jej element wyglądał tak: $array['authors']['author']['Kowalski'] $array['authors']['author']['Nowak'], albo nawet $array['authors']['author']['firstauthor']['Kowalski']?
Ok, po chwili odpoczynku w końcu znalazłem poprawne rozwiązanie:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <!DOCTYPE articlelist [ <!ELEMENT articlelist (article+)> <!ELEMENT article (title,author,shortcontent,hascomments)> <!ELEMENT title (#PCDATA)> <!ELEMENT author (#PCDATA)> <!ELEMENT shortcontent (#PCDATA)> <!ELEMENT hascomments (#PCDATA)> ]> <articlelist> <article> <title>example title</title> <author>example author</author> <shortcontent>example content</shortcontent> <hascomments>example comments</hascomments> </article> </articlelist>
Aktualne jednak pozostaje moje drugie pytanie.
A w międzyczasie zrodziło się kolejne. Używając tego kodu wyżej do przypisywania wartości tablicy array, po wydrukowaniu par klucz => wartość dostaję coś takiego:
articlelist
articlelist
#text
article
#text
title
#text example title
title
#text
author
#text example author
author
#text
shortcontent
#text example content
shortcontent
#text
hascomments
#text example comments
hascomments
#text
article
#text
articlelist