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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:58:27+00:00 2026-06-17T22:58:27+00:00

how do I identify the correct XML node based off a $_POST variable from

  • 0

how do I identify the correct XML node based off a $_POST variable from a user submitted form. Below is my current XML with a note on were I want the new XML data to be placed and the PHP that takes the form data and prepares it to be inserted into the XML document.

XML:

<?xml version="1.0" encoding="UTF-8"?>
    <content_sets>


<!-- The new article node will be placed inside of one of the content_sets child nodes. Either doc_types, video_types, image_types. -->
    <doc_types>

        <article>
            <doc_name>Test Proposal</doc_name>
            <file_name>tes_prop.docx</file_name>
            <doc_description>Test Word document. Please remove when live.</doc_description>
            <doc_tags>word document,test,rfp template,template,rfp</doc_tags>
            <last_update>01/26/2013 23:07</last_update>
        </article>
    </doc_types>



    <video_types>
        <article>
            <doc_name>Test Video</doc_name>
            <file_name>test_video.avi</file_name>
            <doc_description>Test video. Please remove when live.</doc_description>
            <doc_tags>test video,video, avi,xvid,svid avi</doc_tags>
            <last_update>01/26/2013 23:07</last_update>
        </article>
    </video_types>



    <image_types>
        <article>
            <doc_name>Test Image</doc_name>
            <file_name>logo.png</file_name>
            <doc_description>Logo transparent background. Please remove when live.</doc_description>
            <doc_tags>png,logo,logo png,no background,graphic,hi res</doc_tags>
            <last_update>01/26/2013 23:07</last_update>
        </article>
    </image_types>


</content_sets>

PHP on submit:

$file_type = $_POST['file_type'];
//This is where the node name comes from

$doc = new DOMDocument();
$doc->load( 'rfp_files.xml' );

$doc->formatOutput = true;

$r = $doc->getElementsByTagName("content_sets")->getElementsByTagName($file_type);
*****//The above code is where my issue is coming from. I am not identifying the child node of content_sets correctly. 
$b = $doc->createElement("article");

$titleName = $doc->createElement("doc_name");
$titleName->appendChild(
    $doc->createTextNode( $Document_Array["name"] )
);
$b->appendChild( $titleName );


$r->appendChild( $b );

$doc->save("rfp_files.xml");

I did not show the form or the rest of article's child nodes. If needed I can post more of my code.

  • 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-17T22:58:29+00:00Added an answer on June 17, 2026 at 10:58 pm

    When using getElementsByTagName(), you need to use the item() method so you can retrieve a specific node in the node list – even if there is only one item in the node list, you still have to do this.

    getElementsByTagName() will always return a DOM Node List, so you either have to loop through the list, or you have to retrieve a specific item via the item() method – does that make sense? There is an example here: http://php.net/manual/en/domnodelist.item.php

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

Sidebar

Related Questions

I need to identify a fraction from a form field in a recipe database
Garbage collection identify the objects that are no longer referred to by any variable
I am attempting to identify a subset of a range based on TRUE FALSE
I have been trying to find the correct way to sum 2 rows from
I have the problem with loading properties from xml inside jUnit test (the same
I am trying XML::SAX parser for parsing XML file. XML file is shown below,
I need to identify if any checkbox in a CheckBoxList is not checked (
I'm trying to identify if this is an IIS issue or a code issue.
I need to identify basic gestures which are performed in surface application? My final
I want to identify anchor tags that have an href containing a particular string

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.