DOMDocument Load XML giving error & quotes insert error

Posted on 2008-11-13
Last Modified: 2012-05-05
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
Question by:VBpassion
    LVL 10

    Expert Comment

    Use this instead:

    $objDOM = new DOMDocument();
    $objDOM->loadXML(htmlentities($xmlstring, ENT_QUOTES));
    LVL 1

    Author Comment

    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

    LVL 10

    Accepted Solution

    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.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
    What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now