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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:57:43+00:00 2026-06-02T20:57:43+00:00

I am using simplexml to load an API URL in the form of an

  • 0

I am using simplexml to load an API URL in the form of an XML through php. In the ProductDescription element it contains html that I would like to append onto in the warranty section.
I would like to add <li>Valid in US</li> in the ProductDescription element before the LAST </ul> tag:

    <xmldata>
      <Products>
        <ProductCode>ACODE</ProductCode>
        <ProductID>1234</ProductID>
        <ProductName>PRODUCTTITLE</ProductName>
        <ProductDescription>
           <h1>Stuff</h1><p>description</p><hr /><strong>Features &amp; Benefits</strong>
           <ul><li>feat</li><li>feat</li><li>feat</li></ul><hr /><strong>Specifications</strong><ul><li>spec</li><li>spec</li><li>spec</li></ul> <hr /><strong>Warranty Information for a certain product</strong>
           <ul><li>3 Years Parts</li><li>3 Years Labor</li></ul><div> <a href="/ahref" target="_blank">See more products from MFG </a></div>
        </ProductDescription>
        <ProductManufacturer>MFG</ProductManufacturer>
      </Products>
    </xmldata>

Now all I can do is get the bare code out of the ProductDescription, I need to know of a way to add that list tag to end of the last ul tag before posting or displaying. Here is my partial php:

     foreach( $xml as $NEW_XML ) 
        {          
            $code = $NEW_XML->ProductCode;
            $name = $NEW_XML->ProductName;
            $desc = $NEW_XML->ProductDescription; 
            $mfg = $NEW_XML->ProductManufacturer;
echo "<textarea rows='13' cols='64' name='DESC' />" . $desc. "</textarea>"; }

I am hoping I dont have to use REGex as it could be a pain (unless someone knows of a way). My inital thoughts would be to put it into a <textarea> and simply posting it back to an xml, but if there is a way to get to save as an .xml directly that would be more effiecient.

  • 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-02T20:57:44+00:00Added an answer on June 2, 2026 at 8:57 pm

    If the number of uls is known, you can add the information like this:

    $NEW_XML->ProductDescription->ul[2]->addChild('li', 'Valid in US');
    

    This assumes that $NEW_XML is pointing at the Products-Element. To always get the last ul you have to count them first:

    $desc = $NEW_XML->ProductDescription;
    $count = count($desc->ul);
    $desc->ul[$count - 1]->addChild('li', 'Valid in US');
    

    Then you can just output or save $xml->asXML().

    Update:

    Here is the complete code I used, updated according to my assumption from my last comment, maybe this helps:

    <?php
    $xmldata = <<<ENDXML
    <xmldata>
          <Products>
            <Product>
                <ProductCode>ACODE</ProductCode>
                <ProductID>1234</ProductID>
                <ProductName>PRODUCTTITLE</ProductName>
                <ProductDescription>
                   <h1>Stuff</h1><p>description</p><hr /><strong>Features &amp; Benefits</strong>
                   <ul><li>feat</li><li>feat</li><li>feat</li></ul><hr />    <strong>Specifications</strong><ul><li>spec</li><li>spec</li><li>spec</li></ul> <hr /><strong>Warranty Information for a certain product</strong>
                   <ul><li>3 Years Parts</li><li>3 Years Labor</li></ul><div> <a href="/ahref" target="_blank">See more products from MFG </a></div>
                </ProductDescription>
                <ProductManufacturer>MFG</ProductManufacturer>
            </Product>
            <Product>
                <ProductCode>ANOTHERCODE</ProductCode>
                <ProductID>98765</ProductID>
                <ProductName>PRODUCTTITLE 2</ProductName>
                <ProductDescription>
                   <h1>Stuff</h1><p>description</p><hr /><strong>Features &amp; Benefits</strong>
                   <ul><li>feat</li><li>feat</li><li>feat</li></ul><hr /> <strong>Specifications</strong><ul><li>spec</li><li>spec</li><li>spec</li></ul> <hr /> <strong>Warranty Information for a certain product</strong>
                   <ul><li>3 Years Parts</li><li>3 Years Labor</li></ul><div> <a href="/ahref" target="_blank">See more products from MFG </a></div>
                </ProductDescription>
                <ProductManufacturer>MFG</ProductManufacturer>
            </Product>
        </Products>
    </xmldata>
    ENDXML;
    
    $xml = simplexml_load_string($xmldata);
    
    foreach ($xml->Products->Product as $product) {
        $description = $product->ProductDescription;
        $count = count($description->ul);
        $description->ul[$count-1]->addChild('li', 'Valid in US');
    }
    
    echo $xml->asXML();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a basic XML file that I load in my PHP using $xml
I'm using XML for a config file in PHP (Using SimpleXML), in creating the
I have been trying to create an XML using the simplexml library (v2.6.2) http://simple.sourceforge.net/home.php
I'm using a PHP script with SimpleXML to parse an XML feed. I have
When I try to load an HTML file as XML using simplexml_load_string I get
Currently I'm using PHP to load multiple XML files from around the web (non-local)
Hi Im trying to parse an xml feed using simplexml in php. The xml
I have an XML file that needs parsing in PHP. I am currenlty using
i have php function that parses a xml url and gives me an array.this
I'm using this PHP to parse a XML file: <?php $xml = simplexml_load_file(http://api.imgur.com/2/image/zzFV5.xml); echo

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.