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

  • Home
  • SEARCH
  • 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 8089353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:22:08+00:00 2026-06-05T19:22:08+00:00

I am encountering problems writing XML files using PHP. The following is my php

  • 0

I am encountering problems writing XML files using PHP. The following is my php script to write content into an xml file. Basically, no errors have been encountered; but when I check my xml file after running the script, it is empty. Please advice. Thank you.

        $doc= new DOMDocument();
        $doc->load("articles.xml");
        $b = $doc->createElement( "articleDraft" );

          $id = $doc->createElement("id"); 
            $id->appendChild( 
            $doc->createTextNode( $_POST['id'] ) ); 
            $b->appendChild( $id ); 
          $draft=$doc->createElement("draftContent");
          $draft->appendChild($doc->createTextNode($_POST['articleBody']));
          $b->appendChild($draft);
          $time=$doc->createElement("drafTime");
          $draft->appendChild($doc->createTextNode(time()));
          $b->appendChild($time);

        $doc->save("articles.xml");

I am new to writing xml in PHP, please help me identify other problems if you find any. Thank you.

  • 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-05T19:22:09+00:00Added an answer on June 5, 2026 at 7:22 pm

    You simply forgot:

    $doc->appendChild($b);
    

    Edit: If you want to format your output, add:

    $doc->formatOutput = true;
    

    Otherwise your output is not human-friendly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am encountering problems with playing looping sounds using SoundPool and .OGG files. I
I'm using regex snippets to parse smileys into images, and encountering problems with the
I am encountering problems, where when debugging, it's using a port that I dont
I am encountering the following problems trying to work through the quagmire of settings
I have constructed a PHP file which scrapes a web page (using cURL) to
Greetings, I'm using appcelerator to develop some apps, but I'm encountering some problems. Every
I'm new to writing custom ASP.NET server controls, and I'm encountering the following issue:
I've been using zc.buildout more and more and I'm encountering problems with some recipes
I am encountering problems with using images instead of plain text as links for
I'm encountering a problem trying to generalize my algorithm for any-size problems. The code

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.