Environment: win2k, apache, php5.
What I am trying to do: create a simple CMS; loading an xml-object into a textarea for editing (using DOM: $ELEMENTS->nodeValue ).
The problem: when reading an xml-object into the textarea, the xml-tags are omitted. This becomes a problem when there are one or more xml-object levels in the initial node/object.
[INDENT]EXAMPLE: (the "<p>" tags represents the initial node (level 0) and the "<b>" and "<url>" tags represents level 1 nodes/objects)
the XML:
<root><p>What is your <b>destination</b> stranger? <url http=”www.google.com”>Google?</url></p><root>
will OUTPUT: ”What is your destinationstranger?Google?” (or something like that). [/INDENT]
This is bad, because of: if one were to save, the ”<b>” and <url> tags would disappear completely.
Progress hitherto:
[INDENT]1. I simple tried to preserve the original xml tags, so that they would be saved ”as is”. To do this I would need to move the ”<” ”>” entities into and outof the textarea.
I have tried RegEx and htmlentities/html_entity_decode, which didn't work. I believe this was due to the reason I parsed the objects (nodeName/tagName and nodeValue do not (ever?) return the “<” “>” entities, only the content of the requested object/node (this is a newbie-guess). [/INDENT]
[INDENT]EXAMPLE:
function xmlentities( $string ) { return str_replace ( array ( '&', '"', "'", '<', '>' ), array ( '&' , '"', ''' , '<' , '>' ), $string ); }
(the code was taken from one of the PHP.net forums)[/INDENT]
[INDENT]2. Secondly I tried to create something similar to BBcode: by parsing the XML-object and for each new level attach a custom tag. The idea was, when SAVE was initiated, the process would be ”reversed”; for each [tag] the corresponding XML-object would be inserted.[/INDENT]
[INDENT]
<? if(isset($SAVE)) { $ELEMENTS->nodeValue = $_POST[TEXTAREANAME]; }
echo '<textarea name="TEXTAREANAME" cols="100" rows="20">';
if ($ELEMENTS instanceof domElement) { echo trim($ELEMENTS->firstChild->nodeValue); }
foreach ($ELEMENTS->childNodes as $LEVEL1) {
if ($LEVEL1 instanceof domElement) {
echo '[' . $LEVEL1->tagName . ']' . trim($LEVEL1->firstChild->nodeValue);
foreach ($LEVEL1->childNodes as $LEVEL2) {
if ($LEVEL2 instanceof domElement) {
echo '[' . $LEVEL2->tagName . ']' . trim($LEVEL2->firstChild->nodeValue);
foreach ($LEVEL2->childNodes as $LEVEL3) {
if ($LEVEL3 instanceof domElement) {
echo '[' . $LEVEL3->tagName . ']' . trim($LEVEL3->firstChild->nodeValue) . '[/' . $LEVEL3->tagName . ']';
}
}
echo '[/' . $LEVEL2->tagName . ']';
}
}
echo '[/' . $LEVEL1->tagName . ']';
}
}
echo '</textarea>'; ?>
[/INDENT]
[INDENT]The problems with this approach was that: 1) anything after the first occurrence of a tag would not be rendered (e.g. from the XML example above: it would render “What is your destination Google?”; 2) I have no idea how to push the ”reverse” code into the $_POST variable. [/INDENT]
[INDENT]3. While writing this I got an idea to use the PHP-file functions to load the entire XML-file, then using the XML-node to locate the starting/ending point and load that section into the textarea. I'm not sure if that is possible, however, this is my last change for solving this problem (giving that no nice stranger would be kind enough to help me).
[INDENT](Side note: I know that loading an entire xml, without using DOM, (i.e. as a normal file) would print everything (e.g. “<”, “>”).[/INDENT][/INDENT]
Note: the code is executed in a class.
Appreciate any help regarding this issue.
/MWNN