php: replace text in xml doc
- Started
- Last post
- 27 Responses
- vaxorcist0
CDATA is an odd fish.... You have to use it because clients fill in crap from MS-Word and such, always containing illegal characters that fake out the XML parser, but CDATA is a total violation of the whole idea of XML, where structured information should have some order....
of course, the real problem with XML CMS's is that XML demands order and clients demand to be able to re-arrange randomly in my experience...
- rounce0
@felizfeliz: I get that you're frustrated with the speed at how complex these things become, but I find it's like composing a piece of music. You could have all the parts played by the same instrument, but the amount of playing skill and acoustic versatility required, would far outweigh putting in the compartively small amount of effort to find a few more musicians, who are able (and at a standard you require) to play the part you've selected for them.
- felizfeliz0
ok.. finally got the answer thanks to some help:
http://www.phpbuilder.com/board/…
<?php
$dom = new DOMDocument();
$dom->load('test.xml');$nodes = $dom->getElementsByTagName('leaf...
foreach($nodes as $n) {
$n->firstChild->nodeValue = 'Goodbye';
}
$dom->save("test.xml");
echo $dom->saveXML();
?>
- acescence0
well that will set every leaf node to goodbye, but it's close. i still think you're doing this all ass backwards. why not read in the whole doc to a native php datatype, do all your manipulation, then write it all back out to an xml file? you could even just store it in a file as a serialized php object and not have to fuck with dom manipulation, then just overwrite a new xml file when it's updated.
- felizfeliz0
well, ok. but i'm jsut a beginner with php so all that sounds a bit complex to me. I've not been able to find a good tutorial that I can learn from.
- acescence0
i threw this thing together, you're welcome to use it and hack away at it if you'd like. however it uses a DATABASE, but it's all very simple..
all the files are here:
http://culturekiller.com/xml/xml…you need to edit include/configuration.php with your db details
class.page.php in include/objects has the SQL query at the top that will create the table.i never created the delete page, you can figure that out.