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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:15:50+00:00 2026-05-17T18:15:50+00:00

It works properly in the way that it breaks up the comma-separated values into

  • 0

It works properly in the way that it breaks up the comma-separated values into an array (with explode), but when it adds the child nodes, they show up after the closing root tag. What I’m trying to do here is replace the <Genres>Adventure,Crime,Action</Genres> with

<Genre>Adventure</Genre>
<Genre>Crime</Genre>
<Genre>Action</Genre>

A simplified XML source:

<?xml version="1.0" encoding="UTF-8"?>
<root><Product><Genres>Adventure,Crime,Action</Genres></Product></root>

<Genre>Adventure</Genre>
<Genre>Crime</Genre>
<Genre>Action</Genre>

My function:

global $genreArray;
$genres = explode(",",$genreArray->nodeValue);

 foreach ($genres as $genre) {
 $node = $XmlDoc->createElement('Genre', $genre);
 $XmlDoc->appendChild($node);
 }

}

Thanks for any help, I’ve been working on this for days now lol 😉

  • 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-17T18:15:51+00:00Added an answer on May 17, 2026 at 6:15 pm

    The answer was to add a function “insertNewChild” and use it thusly:

        //Convert Genres CSV into individual Genre nodes
    
    global $genreArray;
    if (substr_count($genreArray->nodeValue, ',') > 0) 
        {
        $genres = explode(",",htmlspecialchars($genreArray->nodeValue));
        $genreArray->nodeValue = "";
        $allgenres = $XmlDoc->getElementsByTagName('Genres');
        $parent = $allgenres->item(0);
            foreach ($genres as $genre) 
            {
            $newnode = $XmlDoc->createElement('Genre', $genre);
            insertNewChild($parent,$newnode);
            }
        } 
    else 
    {
    $genre = htmlspecialchars($genreArray->nodeValue);
    $genreArray->nodeValue = "";
    $allgenres = $XmlDoc->getElementsByTagName('Genres');
    $parent = $allgenres->item(0);
    $newnode = $XmlDoc->createElement('Genre', $genre);
    insertNewChild($parent,$newnode);
    }
    

    and the insertNewChild function :

    function insertNewChild($currentNode, $node)
    {
       $currentNode->insertBefore($node, $currentNode->firstChild);   
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following function that works properly in Chrome and Firefox, but not
I'm on ubuntu 12.04 beta. I premit that minicom works properly on /dev/ttyS0 (but
SoundPool works properly on Android 1.6 but when I run on 2.1 in the
I have created a custom ExpandableListAdapter and everything works properly. What I'd like to
In the spirit of the Perl Preamble where a script works properly whether executed
I am making the application for printing the content of JFrame .It works properly
Just like I said, my winform application works properly on computers with VS installed,
I had developed an API Rest for an iPhone Game and it works properly.
I am applying Animation Drawable with some smoke like animation. It works properly everywhere
I have a problem sending POST request with VB6. The code below works properly

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.