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();

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

plz help
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Use this instead:

$objDOM = new DOMDocument();
$objDOM->loadXML(htmlentities($xmlstring, ENT_QUOTES));
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
   <child> sgsgsgssdgsdgsdg</child>
   <child>the mansion & the palace, "dracula" the movie</child>

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 really stuck

I see. You need to apply the htmlentities() function to the content of the xml string and not the xml itself.

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

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

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.