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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:46:35+00:00 2026-06-14T18:46:35+00:00

i am facing a problem in updating my XML using PHP & DOM.My XML

  • 0

i am facing a problem in updating my XML using PHP & DOM.My XML file is in this format:

Original XML (& desired xml layout):

<?xml version="1.0" standalone="yes"?>
<Rows>
  <Row CustomerAccountNumber="COU002" />
  <Row CustomerAccountNumber="COU023" />
  <Row CustomerAccountNumber="C2335" />
  <Row CustomerAccountNumber="CvbU002" />

And the code that saves i.e adds the new record to the XML(customer.xml) is:

<?php

$xmldoc=new DOMDocument();
$xmldoc->load('XML/customer.xml');

$newAct= 'c12345';

$root = $xmldoc->firstChild;

$newElement= $xmldoc->createElement('CustomerAccountNumber');
$root->appendChild($newElement);
$newText= $xmldoc->createTextNode($newAct);
$newElement->appendChild($newText);

$xmldoc->save('XML/customer.xml');
 ?>

Issue : The Code is generating the new record in this format:

  <Rows>
  <Row CustomerAccountNumber="COU002" />
  <Row CustomerAccountNumber="COU023" />
  <Row CustomerAccountNumber="C2335" />
  <Row CustomerAccountNumber="CvbU002" />
  <CustomerAccountNumber>c12345</CustomerAccountNumber>

</Rows>

I couldn’t understand where i am making mistake.All i want to retain my original XML format.I want output file in the above mentioned original format(See top).Kindly guide me and point me where i am making mistake that is generating incorrect format within the file itself.Plz help

  • 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-14T18:46:36+00:00Added an answer on June 14, 2026 at 6:46 pm

    Your issue is that you are currently creating a new CustomerAccountNumber element. Instead, you want to create a new Row element, and then create a new CustomerAccountNumber attribute:

    $newElement = $xmldoc->createElement('Row');
    $newAttribute = $xmldoc->createAttribute('CustomerAccountNumber');
    $newAttribute->value = $newAct;
    $newElement->appendChild($newAttribute);
    $root->appendChild($newElement);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am facing problem for reading xml file using javascript. It works fine in
I am facing problem in updating the form view values using sqldatasource bind with
I am facing problem while connecting cake php version-2.0.0-dev application on server. When I
I am facing problem while GWT compilation. I am using ANT build file in
iam facing problem in passing array to view. this is my controller code.. function
I am facing problem with UIPanGestureRecognizer. suppose i am adding 10 button dynamicaly using
I am facing problem with the control flajaxian.FileUploader i.e. after downloading the dll file
Im facing problem with poor performance of css prompting mechanism. Can I dissable this
I am facing problem while upgrading an Higher version over Lower version. I have
i m facing a problem with WebResponse Property it is not properly updating in

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.