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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:00:01+00:00 2026-06-07T16:00:01+00:00

I am using SimpleXML to load a remote XML My PHP code looks like

  • 0

I am using SimpleXML to load a remote XML

My PHP code looks like below

$xml = simplexml_load_file('http://www.abc.om/xml.php');

foreach( $xml as $Product )
    {
        echo 'ProductCode: '.$Product->ProductCode.'<br />';
        echo 'ProductName: '.$Product->ProductName.'<br />';

    } 

MY XML looks like below

<All_Products>
<Product>
<ProductCode>9978H</ProductCode>
<ProductName>abc with Buckle in aBlack</ProductName>
<StockStatus>2</StockStatus>
</Product>
</All_Products>

Product tags are repeated as there are many products

after reading that XMLfeed the XML feed should display with some ammends that is before
<StockStatus> tag it should add a tag

<ProductURL><ProductURL>

and that tag should display like

<ProductURL>http://abc.com/abc with Buckle in aBlack-p/9978H.htm<ProductURL>

That means each ProductURL should be appended as

<ProductURL>http://abc.com/<ProductName>-p/<ProductCode>.htm<ProductURL>

The final XML to display will look like

<All_Products>
<Product>
<ProductCode>9978H</ProductCode>
<ProductName>abc with Buckle in aBlack</ProductName>
<ProductURL>http://abc.com/abc with Buckle in aBlack-p/9978H.htm<ProductURL>
<StockStatus>2</StockStatus>
</Product>
</All_Products>

So my questions are

1) Do i have to read all the elements of the Product tag in the foreach( $xml as $Product ) loop and then append ProductURL element or is there any shortcut to do it

2) Once this data is ready how do i again display the data in XML format

  • 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-07T16:00:04+00:00Added an answer on June 7, 2026 at 4:00 pm

    You can use DOM with SimpleXML.

    Here’s what you should do:

    1. Use xpath() to run an xpath query that picks out all the Product tags. This should return you an array of SimpleXMLElements representing each Product tag.

    2. Use xpath() again to select from each Product tag the ProductCode and ProductName and get their contents. Create your url and save it to a variable.

    3. Use xpath() to select the StockStatus tag.

    4. Using DOM’s dom_import_simplexml(), convert the SimpleXMLElement StockStatus tags to a DOMElement.

    5. Create the ProductURL element using DOM’s createElement() and insert the url we created before.

    6. Insert it before StockStatus using DOM’s insertBefore().

    This question should show you how to do the conversion to a DOMElement and finally do the insertion.

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

Sidebar

Related Questions

I am currently using: $page = simplexml_load_file('http://www.example.com/page.html'); In my code I would like to
How do I convert SOAP response like this to php array using SimpleXML? <?xml
Simple one guys. I have an XML parsed using simplexml_load_file(). The following code: <?php
I'm trying to load a gzipped XML file using simplexml_load_file() PHP function, but I
I'm using this PHP to parse a XML file: <?php $xml = simplexml_load_file(http://api.imgur.com/2/image/zzFV5.xml); echo
I'm using XML for a config file in PHP (Using SimpleXML), in creating the
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 am using the PHP SimpleXML way of working with XML files on my
I want to parse (little critical) xml using php simplexml...But i can aither get

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.