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

My code works great in IE8, Firefox and Safari. But it doesn't work properly
I'm trying to figure out whats the best way to get checkboxes to properly
I'm having trouble getting a rotary encoder to work properly with AVR micro controllers.
It seems like searching with CAML and SPQuery doesn't work properly against custom metadata,
In Classic ASP, Server.MapPath() doesn't always work properly in the Application_OnStart event within global.asa
Alright, I'm trying to get arguments to work properly with a small test application.
Python works on multiple platforms and can be used for desktop and web applications,
Silverlight works on client side so putting any sensitive data like connection strings, passwords
This works (prints, for example, 3 arguments): to run argv do shell script echo
So, I had a question about getting word count to work properly in emacs

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.