DOMDocument Load XML giving error & quotes insert error

Hello All
I have a user form and the clients fill the information. On submit, Im making it as XML and posting it to XML. Now the problem happend when sombody enters any special chanrachters like "&" or double quotes. then the xml is not loaded. it but if a plain text is inserted then its all fine.
The user on the web is free to insert any text in the textbox, so how can i tackle this problem.
Secondly, what if in the text user inserts " double quotes, then my query gives error.
I tried using addslash but for some reason it doesn\t work.

$objDOM = new DOMDocument();
$objDOM->loadXML(addslashes($xmlstring));

above is the code for loading the xmlstring which is posted by the form.

plz help
LVL 1
VBpassionAsked:
Who is Participating?
 
ray-solomonCommented:
I see. You need to apply the htmlentities() function to the content of the xml string and not the xml itself.

For Example:
<mainnode>
   <child> sgsgsgssdgsdgsdg</child>
   <child>the mansion & the palace, "dracula" the movie</child>
</mainnode>

will be this:
<mainnode>
   <child> sgsgsgssdgsdgsdg</child>
   <child>the mansion &amp; the palace, &quot;dracula&quot; the movie</child>
</mainnode>


You can do this by finding the script that is generating the xml code for the $xmlstring variable and applying the htmlentities to the content between the element nodes.

If you show me the code for that I can help you determine where to use the htmlentities() function.


0
 
ray-solomonCommented:
Use this instead:

$objDOM = new DOMDocument();
$objDOM->loadXML(htmlentities($xmlstring, ENT_QUOTES));
0
 
VBpassionAuthor Commented:
Hi i did that, now its saying,
Warning: DOMDocument::loadXML() [function.DOMDocument-loadXML]: Start tag expected, '<' not found in Entity.

Just to let u know my XML which is posted is this
<mainnode>
   <child> sgsgsgssdgsdgsdg</child>
   <child>the mansion & the palace, "dracula" the movie</child>
</mainnode>

What i understand from the above errror is, when i say the xmlobject is unable to find the < tag because of the fucntion which u asked me to do. or may be somethign else..

kindly help to resolved....im really stuck

Regards
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.