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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:25:42+00:00 2026-06-10T10:25:42+00:00

I have code which add item like below to xml file: <newWord> <Heb>rer</Heb> <Eng>twew</Eng>

  • 0

I have code which add item like below to xml file:

<newWord>
  <Heb>rer</Heb>
  <Eng>twew</Eng>
</newWord>

the problem is when I add element it will be not in the right place, it is out from xml tag like below.

<?xml version="1.0" encoding="UTF-8"?>
<xml>
  <newWord>
    <Heb>hebword</Heb>
    <Eng>banna</Eng>
  </newWord>
</xml>
<newWord>
  <Heb>rer</Heb>
  <Eng>twew</Eng>
</newWord>

How can I add the new element to correct place? thx

my code:

<?php    

    $wordH=$_GET['varHeb'];
    $wordE=$_GET['varEng'];


    $domtree='';

        if(!$domtree)
        {   
            $domtree = new DOMDocument('1.0', 'UTF-8');
            $domtree->formatOutput = true;
            $domtree->load('Dictionary_user.xml');
        }

        $Dictionary_user = $domtree->documentElement;

    $currentitem = $domtree->createElement("newWord");
    $currentitem = $domtree->appendChild($currentitem);

    $currentitem->appendChild($domtree->createElement('Heb', $wordH));
    $currentitem->appendChild($domtree->createElement('Eng',$wordE));

    $Dictionary_user->childNodes->item(0)->parentNode->insertBefore($currentitem,$Dictionary_user->childNodes->item(0));
        header("Content-type: text/xml");

    $domtree->save("Dictionary_user.xml");
    /* get the xml printed */
    echo $domtree->saveXML();
?>
  • 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-10T10:25:43+00:00Added an answer on June 10, 2026 at 10:25 am

    Perhaps you want something like:

    <?php 
    if(!empty($_GET['varHeb']) && !empty($_GET['varEng'])){
        //Dont forget utf-8 if using Hebrew letters
        header('Content-type: text/xml; charset=utf-8');
        //Load It
        $xml = simplexml_load_file('./Dictionary_user.xml');
    
        //Add a new node & add the children
        $node = $xml->addChild('newWord');
        $node->addChild('Heb', trim($_GET['varHeb']));
        $node->addChild('Eng', trim($_GET['varEng']));
    
    
        //DOMDocument to format code output
        $dom = new DOMDocument('1.0', 'UTF-8');
        $dom->preserveWhiteSpace = false;
        $dom->formatOutput = true;
        $dom->loadXML($xml->asXML());
    
        echo $dom->saveXML();
    }else{
        //params not set for $_GET
    }
    
    /**
     * Result
    <?xml version="1.0" encoding="UTF-8"?>
    <xml>
      <newWord>
        <Heb>hebword</Heb>
        <Eng>banna</Eng>
      </newWord>
      <newWord>
        <Heb>אנחנו אוהבים גלישת מחסנית</Heb>
        <Eng>We Love Stack overflow</Eng>
      </newWord>
    </xml>
    */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have code, which does something like this: item.previous.parent.parent.aTag['href'] now i would like to
I have following code: os.chdir(os.path.dirname(os.path.realpath(__file__)) + /../test) path.append(os.getcwd()) os.chdir(os.path.dirname(os.path.realpath(__file__))) Which should add /../test to
I have the following php code which I want to add a delay too:
i have this javascript code to which i want to add the jquery fade-in
I have code which needs to do something like this There is a list
I have code which looks like: private static DirectiveNode CreateInstance(Type nodeType, DirectiveInfo info) {
I have the code below which is intended to build a dictionary object with
I have a database return result which has flatten results like below. I want
I have code which has a drop down list. And when a certain option
I have code which as been working against an older Active Directory server and

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.