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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:51:02+00:00 2026-05-24T16:51:02+00:00

I spent days figuring and reading about how to produce an xml file from

  • 0

I spent days figuring and reading about how to produce an xml file from a table in my db. I got it working fine and produces a valid xml file for me to parse. This file contains over 13000 records and I only need to pull records to display to the user where a certain xml field (category) contains data. Can this be done? The only other way I can think is to filter those records through the php script that is pulling the records and producing the xml file. Any assistance is appreciated. My code is below that I am using to create the xml and the client side jquery code to display the xml contents. I know my jquery script only is showing 2 of the xml fields because of testing.

Thanks.

PHP code to produce the xml file

$query = "SELECT name,test_code,cpt_code,components FROM tm_test";
$result = mysql_query($query);


$doc = new DomDocument('1.0');

header('Content-Type: application/xml; charset=ISO-8859-1');

// create root node
$root = $doc->createElement('tests');
$root = $doc->appendChild($root);

while($array = mysql_fetch_array($result)) {

// add node for each row
$occ = $doc->createElement('test');
$occ = $root->appendChild($occ);

$child = $doc->createElement('name');
$child = $occ->appendChild($child);
$value = $doc->createTextNode($array['name']);
$value = $child->appendChild($value);

$child = $doc->createElement('test_code');
$child = $occ->appendChild($child);
$value = $doc->createTextNode($array['test_code']);
$value = $child->appendChild($value);

$child = $doc->createElement('cpt_code');
$child = $occ->appendChild($child);
$value = $doc->createTextNode($array['cpt_code']);
$value = $child->appendChild($value);

$child = $doc->createElement('components');
$child = $occ->appendChild($child);
$value = $doc->createTextNode($array['components']);
$value = $child->appendChild($value);

$child = $doc->createElement('method');
$child = $occ->appendChild($child);
$value = $doc->createTextNode($array['method']);
$value = $child->appendChild($value);

$child = $doc->createElement('clinical_indication');
$child = $occ->appendChild($child);
$value = $doc->createTextNode($array['clinical_indication']);
$value = $child->appendChild($value);

$child = $doc->createElement('category');
$child = $occ->appendChild($child);
$value = $doc->createTextNode($array['category']);
$value = $child->appendChild($value);
}

$doc->save('testlist.xml');

echo $doc->saveXML();
?>

jQuery script to display all records

  $(document).ready(function(){

                            $.ajax({
                                   type: "GET",
                                   url: "testlist.xml",
                                   dataType: "xml",
                                   success: parseXml
                                   });
                            function parseXml(xml) {
                            $(xml).find('test').each(function(){
                                  $("#testList").append('<li><div   data-role="collapsible" data-collapsed="true" data-theme="b"><h3>' + $(this).find("name").text() + '</h3>' + '<p>' + $(this).find("test_code").text() + '</p></div></li>');

                                                     });
                            }
                            });
  • 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-24T16:51:03+00:00Added an answer on May 24, 2026 at 4:51 pm

    Just pass the desired category in your ajax call to PHP.

    $.ajax({
        type: "GET",
        url: "testlist.xml",
        data: "category=the_category_you_want",
        dataType: "xml",                                   
        success: parseXml
    });
    

    The category will be available to your PHP script as $_GET['category'].

    Change your SQL query to filter by this category using a WHERE clause:

    $query = "SELECT name,test_code,cpt_code,components FROM tm_test   
              WHERE category = ?";
    

    and bind the variable value (to prevent SQL injection).

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

Sidebar

Related Questions

I have spent last 3 days until I got gps working on android using
I have spent several days now researching Hibernate and have several small questions about
I got 3 arrays in PHP 1. Place name - $places 2. Days spent
I spent the last three days working on the collection _ select form helper
After having spent two days attempting to rasterize jpeg's from SVG strings using ImageMagick
I started to write an installer with WiX. I've spent several days reading blogs
I'm working on a web server for Android and even though I've spent days
I've got code that I am using from another team and I have spent
I spent days working on a function to get common chars in an array
I spent days to search about this topic and I found some good articles,

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.