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 964803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:53:23+00:00 2026-05-16T01:53:23+00:00

I am a beginner in PHP and I know nothing about XML manipulation. I

  • 0

I am a beginner in PHP and I know nothing about XML manipulation. I am working on a Google CSE annotation XML shown below:

  <?xml version="1.0" encoding="UTF-8" ?> 
- <Annotations>
- <Annotation about="http://sanspace.in/">
  <Label name="_cse_byxamvbyjpc" /> 
  </Annotation>
- <Annotation about="http://blog.sanspace.in/">
  <Label name="_cse_byxamvbyjpc" /> 
  </Annotation>
- <Annotation about="http://google.com/">
  <Label name="_cse_exclude_byxamvbyjpc" /> 
  </Annotation>
  </Annotations>

I want achieve this from the above shown file:

  <?xml version="1.0" encoding="UTF-8" ?> 
- <Annotations>
- <Annotation about="http://sanspace.in/">
  <Label name="testString1" /> 
  </Annotation>
- <Annotation about="http://blog.sanspace.in/">
  <Label name="testString2" /> 
  </Annotation>
- <Annotation about="http://google.com/">
  <Label name="testString2" /> 
  </Annotation>
  </Annotations>

So far, I have tried:

<?php
if (file_exists('test.xml'))
  {
  $xml = simplexml_load_file('test.xml');
  }
else
  {
  exit('Error.');
  }
foreach($xml->Annotation as $annotation)
    {
    if ($annotation["about"]=="http://sanspace.in/") 
        {  $annotation->Label["name"]="testString1";  } 
    else 
        {  $annotation->Label["name"]="testString2";  } } 

$dom = new DOMDocument('1.0'); 
$dom->preserveWhiteSpace = false; 
$dom->formatOutput = true; 
$dom->loadXML($xml->asXML()); 
echo $dom->saveXML();
$dom->save("test.xml");
?> 

This code performs the task but it doesn’t save it into the file.

My question is, what’s wrong with the $dom->save("test.xml"); statement?
How do I save the XML file on the server?

  • 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-05-16T01:53:24+00:00Added an answer on May 16, 2026 at 1:53 am

    I don’t see anything wrong with your code. I think you have a permission problem.

    PHP is running as one of the following two users:

    • nobody or possibly www-data (aka the system user the web server uses)
    • Your user name

    For PHP to run as the user that owns the web root (i.e. you), suexec has to be enabled for PHP. The fact that you can’t write to a file with 0644 permissions pretty much says that it is not.

    You have two options:

    • Re-configure the server so PHP runs as the user that owns the web root
    • Make the file world write-able

    I highly recommend the first over the second. However, you don’t always have that choice. If your host (or sysadmin, or whoever) can’t or won’t enable suexec for PHP, you’ll have to give the file 0777 permissions, aka rwxrwxrwx.

    You might want to login via ssh and create the output file using the touch command first (or directory, if that’s what you need via mkdir), then give it the needed permissions.

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

Sidebar

Ask A Question

Stats

  • Questions 491k
  • Answers 491k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer First a simpler problem: suppose you just wanted to use… May 16, 2026 at 10:02 am
  • Editorial Team
    Editorial Team added an answer Give your window element position: fixed; in the CSS. Position… May 16, 2026 at 10:02 am
  • Editorial Team
    Editorial Team added an answer got the solution.Its just that i had to use the… May 16, 2026 at 10:02 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

i know nothing about ruby but a lot about php. when you code in
Over the last year I have moved from a beginner PHP developer to a
I am beginner in PHP and i read in manual that $_REQUEST is a
I am a beginner in PHP. How can I restrict user access to controller.php
I'm beginner with iPhone and want to know how to add a view in
Ok, I am an absolute beginner in powerbuilder. Currently I am working in a
This is a beginner's rails learning confusion. When I learn rails, from time to
I'm a beginner in web development, and I'm trying to insert line breaks in
The original question is below, but I changed the title because I think it
so i read stuff about how apache's mod_rewrite does the trick but it seems

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.