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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:55:46+00:00 2026-06-14T11:55:46+00:00

I have a company that provides a data feed for a search tool but

  • 0

I have a company that provides a data feed for a search tool but I must build the search tool. The products inventory changes hourly, which is why they have a feed for the product information. I can pull the feed in to populate a search form where customers can search on my site to see if a product is available by that vendor.

Can someone point me in the right direction to parse the XML feed and display the results as a dropdown in a form? Once they select the first item which is ‘Style’ then a new box should appear called ‘Color’ which again is returned from the feed in a second call (I think it would be a second call passing the parameter the form gathered in the first selection.

I’m not asking anyone to write this for me but I’m new to cURL (which I’m thinking I need to use) and SimpleXML and just need links to good relevant tutorial or some advice.

  • 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-14T11:55:48+00:00Added an answer on June 14, 2026 at 11:55 am

    Well, it’s not very clear how you want things to happen so it’s difficult to give you advice to whether consuming the XML Feed server-side or client side.

    Besides, you haven’t explained how you can “obtain” the xml feed. Is it a webservice that requires authentication? What type of request is it? Or it’s simply a file residing in somewhere on the interwebs? Or is it available locally?

    I’m going to assume the feed you’re consuming does not require complicated requests or authentication.

    So here’s an AJAX example using with jQuery and a GET request

    XML Example (productsfeed.xml)

    <products>
        <product id="prod1" name="iMac" price="2000" vendor="Apple">
            <stock>10</stock>
        </product>
        <product id="prod2" name="iPad" price="500" vendor="Apple">
            <stock>50</stock>
        </product>
        <product id="prod3" name="Galaxy S3" price="500" vendor="Samsung">
            <stock>100</stock>
        </product>
    </products>
    

    Example HTML with ajax call and a dropdown with products.

    <!DOCTYPE HTML>
    <html>
        <head>
            <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
            <script>
            $(document).ready(function(){
                $.ajax({
                    url: 'http://myhost.com/webservice', // Url to the webservice or feed
                    // Here goes all the "shenanigans" regarding the web service, like
                    // request type, headers to send, etc..
                    success: function(xml) {
                        $(xml).find('product').each(function(){
                            var id     = $(this).attr('id');
                            var name   = $(this).attr('name');
                            var price  = $(this).attr('price');
                            var vendor = $(this).attr('vendor');
                            var stock  = $(this).find('stock').text();
    
                            var $selectItem = $('<option></option>');
                            $selectItem.attr('value', id);
                            $selectItem.attr('data-id', id);
                            $selectItem.attr('data-price', price);
                            $selectItem.attr('data-vendor', vendor);
                            $selectItem.attr('data-stock', stock);
                            $selectItem.html(name);
    
                            $selectItem.appendTo('#plist');
                        });
    
                    }
                });
            });
            </script>
        </head>
        <body>
            <div><span>Product List</span></div>
            <div id="plist-wrapper">
                <select id="plist">
    
                </select>
            </div>
        </body>
    </html>
    

    Now with PHP

    If it’s a webservice you can use cURL

    $url = 'http://myhost.com/webservice';
    
    // HTTP Headers to send to the webservice
    // specific to the webservice you're consuming
    $headers = array();
    
    $ch = curl_init();
    
    // curl_setopt to set the options
    // see http://www.php.net/manual/en/function.curl-setopt.php
    curl_setopt($ch, CURLOPT_URL, $url);
    
    //headers if needed
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    
    // Send the request and check the response
    if (($result = curl_exec($ch)) === FALSE) {
        echo 'Failed with' . curl_error($ch) . '<br />';
    } else {
        echo "Success!<br />\n";
    }
    curl_close($ch);
    

    If it’s not a webservice (just a xml file) you can use file_get_contents

    $result = file_get_contents('http://myhost.com/productsfeed.xml');
    

    To parse the xml and show the dropdown select menu

    $xml = new DOMDocument();
    $xml->loadXML($result);
    
    $html = new DOMDocument();
    $htmlSource = 
    '<html>
        <head></head>
        <body>
            <div><span>Product List</span></div>
            <div id="plist-wrapper">
                <select id="plist"></select>
            </div>
        </body>
    </html>';
    
    $html->loadHTML($htmlSource);
    $selectList = $html->getElementsByTagName('select')->item(0);
    $optionItem = $html->createElement('option');
    
    $prodNodeList = $xml->getElementsByTagName('product');
    
    foreach ($prodNodeList as $prodNode) {
        $id     = $prodNode->getAttribute('id');
        $name   = $prodNode->getAttribute('name');
        $price  = $prodNode->getAttribute('price');
        $vendor = $prodNode->getAttribute('vendor');
    
        $option = clone $optionItem;
        $option->setAttribute('value', $id);
        $option->setAttribute('data-id', $id);
        $option->setAttribute('data-price', $price);
        $option->setAttribute('data-vendor', $vendor);
        $option->nodeValue = $name;
        $selectList->appendChild($option);
    }
    
    print $html->saveHTML();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a web service that provides auto insurance quotes and a company that
I have made a web application to a company that provides users to input
I have a problem with creating a tool that's provides a custom overlay on
I have Company that has many Phones. I created seed data to add 1
I have an entity Company that has many Orders. I mapped these as following
I have a small website for a company that have 40-50 product. The site
I have a model called company that has_many users then users belongs_to company. class
I have a class called 'Company' that has properties like 'CompanyName', 'CompanyCode' and 'IsActive'.
I have an old project at our company that uses shell scripting a lot.
I have a web application from a company that has gone out of business.

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.