Hi all
How to addChild to simpleXML node if it has html entities?
I did tryit doesn't workCode:myXML->addChild('form','<textfield>Hello World</textfield>');
Hi all
How to addChild to simpleXML node if it has html entities?
I did tryit doesn't workCode:myXML->addChild('form','<textfield>Hello World</textfield>');
Last edited by LOLFlash; 04-08-2010 at 07:13 PM.
I'm not sure, but I'm guessing that this might be confusing because XML and HTML use the same syntax (generally) so the processor gets confused when you are adding xml text to an xml object and everything will get messy.
Suggestions:
1. Use a more complex xml processor (if possible, I don't know)
2. Use a database (ALWAYS a good idea especially when it starts getting complex like this)
3. Escape the html characters, such as > to >. You can use functions like htmlentities() for this.
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
Thanks for replay
what I want is to change my simpleXML node data
I have data in XMLfile
sourseXML=simplexml_load_file($link);
and I want to change first node so my output comes in:HTML Code:<htm> <div><p>Hi Everyone</p></div> <div><p>Hi Second time</p></div> </htm>
echo sourseXML->asXML()
HTML Code:<htm> <div><form><textarea><p>Hi Everyone</p><textarea></form></div> <div><p>Hi Second time</p></div> </htm>
what technique I can use?
Moderator's note - LOLFlash's most recent post in this thread was automatically flagged by the board for some reason as possibly X rated or spam. This happens sometimes (rarely). I can't see why in this case though. Anyways, I have approved the post and deleted the others that were simply understandable duplicate attempts to post the information/question.
If this happens again LOLFlash, just be patient. I or one of the other mods will approve/validate the post soon as long as there is nothing bad in it, which obviously there isn't.
If anyone has any idea why the last post in this thread by LOLFlash was flagged by the board I'd love to know. Perhaps we can remove an overly aggressive keyword or change something else that caused this obviously genuine post to get flagged by the board.
LOLFlash, please accept our apologies and bear with us on this.
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
Thanks jscheuer1
just put a note on top of publish button with attention to wait and any flagged feedback will be helpful
I didn't know I sent and tried different buttons to rich djr33 while he was online
so "Post Replay" button didn't work and I used "Post Quick Replay" after all
Regarding PHP question
is anyone knows how to attaches CDATA to simpleXML?
I have filtered my xml with xpath
now I want replace node 2 text with text consisting html tags so my output will be
so my output:
what is OK for meCode:<htm> <div><p><![CDATA[<form> <textarea> <p>Hi Everyone</p> <textarea></form>]]></p></div> <div><p>Hi Second time</p></div> </htm>
but how to switch node 2 from text to CDATA?
I don't want to rebuild whole XML for purpose change only one node properties
I can access text through node[1][0] after xpath but I cant make it carrying html tags
any help appreciate
Last edited by LOLFlash; 04-09-2010 at 09:21 PM.
the most semantic way would be to add the <p> content as another xml tag:
you could then access the content normally and add the html tags via your php script:Code:<?xml version="1.0"?> <htm> <div> <p> Hi Everyone </p> </div> </htm>
the alternative would be to rewrite your xml - perhaps using BBCode-style tags - and then usePHP Code:<?php
$sourseXML=simplexml_load_file($link);
echo '<p>'.$sourseXML->htm->div->p.'</p>';
?>preg_replace()to convert it all. As djr mentions, it would be simpler to use a database. If you're not searching/manipulating the contents of this file, you could also simply save it as a text file and justinclude()it directly.
Last edited by traq; 04-10-2010 at 01:05 AM.
Bookmarks