Galtrhan Posted September 2, 2008 Report Share Posted September 2, 2008 (edited) XML struktūra: <main> <item attr="value" /> <item attr="value" /> <item attr="value" /> </main> PHP fails: <?php $dom = new DOMDocument(); $dom->load("test.xml"); //$root = $dom->createElement("main"); //$dom->appendChild($root); $item = $dom->createElement("item"); $root->appendChild($item); $attr = $dom->createAttribute("attr"); $item->appendChild($attr); $val = $dom->createTextNode("value"); $attr->appendChild($val); $dom->save("test.xml"); echo $dom->saveXML(); ?> Kas man šei jāizmaina lai kods darbotos - ielādētu xml failu -> pievienotu jaunu <item> -> saglabātu. Tas ko es nemāku ir, ielikt $root mainīgajā pirmo (arī vienīgo) <main> elementu. Citādi liekas vajadzētu pārējam iet... Edited September 2, 2008 by Galtrhan Link to comment Share on other sites More sharing options...
andrisp Posted September 2, 2008 Report Share Posted September 2, 2008 Hmm, man gan liekas, ka tev vajag šitā kaut kā: $root = $dom->getElementsByTagName('main'); $root = $root::item(0); Es gan galīgi nezinu vai šitas strādās, jo ar domdocument nekad neesmu strādājis, un šito tīri pēc dokumentācijas uzdrukāju. :) Link to comment Share on other sites More sharing options...
Galtrhan Posted September 2, 2008 Author Report Share Posted September 2, 2008 Ok, paldies. Tūlīt pārbaudīšu. Link to comment Share on other sites More sharing options...
Galtrhan Posted September 2, 2008 Author Report Share Posted September 2, 2008 (edited) Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM in /myserver/xmltest.php on line 11 laikam uz servera ne tāda valoda, jo no tā errora neko nesaprotu... un tā 11 rinda ir šī te: $root = $root::item(0); Edited September 2, 2008 by Galtrhan Link to comment Share on other sites More sharing options...
PheliX Posted September 2, 2008 Report Share Posted September 2, 2008 T_PAAMAYIM_NEKUDOTAYIM ir dubultkols "::" Link to comment Share on other sites More sharing options...
andrisp Posted September 2, 2008 Report Share Posted September 2, 2008 (edited) Jā, es bik saputroju. Vajag $root->item(0); PS. http://lv2.php.net/manual/en/language.oop5...nekudotayim.php Edited September 2, 2008 by andrisp Link to comment Share on other sites More sharing options...
Galtrhan Posted September 2, 2008 Author Report Share Posted September 2, 2008 Ok, paldies. Tagad viss strādā. Link to comment Share on other sites More sharing options...
Recommended Posts