Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8606057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:00:15+00:00 2026-06-12T03:00:15+00:00

I have a textarea in which I prints all my xml like this: <form

  • 0

I have a textarea in which I prints all my xml like this:

<form method="post" action="">
<textarea id="codeTextarea" name="thisxml" cols="100" rows="36">
<?php
$xml = new DOMDocument();
$xml->formatOutput = true;
$xml->preserveWhiteSpace = false;
$xml->loadXML('<?xml version="1.0" encoding="ISO-8859-1"?>
<data>
  <game id="103478">
    <opponent>Peter</opponent>
    <oppid>4</oppid>
    <lastdraw>0</lastdraw>
  </game>
  <game id="103479">
    <opponent>Peter</opponent>
    <oppid>4</oppid>
    <lastdraw>2</lastdraw>
  </game>
  <game id="103483">
    <opponent>James</opponent>
    <oppid>47</oppid>
    <lastdraw>2</lastdraw>
  </game>
</data>');

echo htmlspecialchars($xml->saveXML()); 
?>
</textarea>

I then on submit want to create/update the file with the new xml but all I get in the new xml document is this:

<?xml version="1.0"?>

I try to save the xml like this with PHP:

$myFile = 'TEST.xml';
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = htmlspecialchars($_POST['thisxml']);
fwrite($fh, $stringData);
fclose($fh);

Can somebody please tell me what I am doing wrong?

Thanks in advance 😉

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:00:17+00:00Added an answer on June 12, 2026 at 3:00 am

    Using htmlspecialchars($_POST['thisxml']) would make your XML invalid an return something like

    &lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?&gt;
    &lt;data&gt;
      &lt;game id=&quot;103478&quot;&gt;
        &lt;opponent&gt;Peter&lt;/opponent&gt;
        &lt;oppid&gt;4&lt;/oppid&gt;
        &lt;lastdraw&gt;0&lt;/lastdraw&gt;
      &lt;/game&gt;
      &lt;game id=&quot;103479&quot;&gt;
        &lt;opponent&gt;Peter&lt;/opponent&gt;
        &lt;oppid&gt;4&lt;/oppid&gt;
        &lt;lastdraw&gt;2&lt;/lastdraw&gt;
      &lt;/game&gt;
      &lt;game id=&quot;103483&quot;&gt;
        &lt;opponent&gt;James&lt;/opponent&gt;
        &lt;oppid&gt;47&lt;/oppid&gt;
        &lt;lastdraw&gt;2&lt;/lastdraw&gt;
      &lt;/game&gt;
    &lt;/data&gt;
    

    Just use file_put_contents it combines the functions of fopen , fwrite , fclose

    file_put_contents('TEST.xml', $_POST['thisxml']);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code. print( <form action='home.php' method='POST'> <textarea name='changemainhometa' id='msgpost'> $home </textarea>
I have a Textarea which is in a form that has this value Hello<div
I have a textarea form which takes a large block of text. In this
i have html form with textarea in which i paste some XML, for example:
I run into this problem. I have a textarea which I only want to
I have a textarea on my page. It has this draggable corner which lets
I would like to have some functionality by which if I write <textarea maxlength=50></textarea>
I have a simple textarea which works in all browsers i.e. I can click
I have a textarea which is a tinymce editor. This text area contains html.
I have a textarea which post plane text to mysql db table. Now I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.