My XML file contains the contents of several web pages. Example:
Expand|Select|Wrap|Line Numbers
- <allPages>
- <thisPage>
- <h1>Page Title</h1>
- <p>Some text, which contains an <a href="link.php">inline link.</a></p>
- </thisPage>
- <anotherPage>
- <p>you get the <b>idea</b></p>
- </anotherPage>
- </allPages>
I thought this would be a really great idea and very simple to implement, but there's a problem: my inline links do not display.
Actually, the first version of my PHP script didn't import any of the page elements at all, it just spat out a plaintext blob with no markup whatsoever. So I revised it and now the script reads:
Expand|Select|Wrap|Line Numbers
- $myXML = new DOMDocument();
- $myXML->load('includes/content.xml');
- $aboutNode=$myXML->getElementsByTagName('about')->item(0);
- $start = $aboutNode->firstChild;
- $content = "";//initialize the variable as an empty string
- for($i=0;$i<$aboutNode->childNodes->length; $i++){
- if($start->nodeType !=3){//if the node is an element
- $snt = $start->nodeName;
- $content .= '<'.$snt.'>';
- $content .= $start->nodeValue;
- $content .= '</'.$snt.'>';
- }
- $start=$start->nextSibling;
- }
- echo $content;//display the output
And that worked great! Except it still does not deal with my inline links. They are missing. Apparently markup elements (such as inline links) are not treated as child nodes by the parser?
In JavaScript you can just use innerHTML to achieve this. In my Google quest I found a PHP script on someone's blog that supposedly emulates the innerHTML function but it was very complicated. It seems like this process must be done all the time without resorting to complex workarounds.
So my question is, what's the simplest way to import a node's contents, including markup? I can't figure it out. Thanks very much!
-thesmithman