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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:13:37+00:00 2026-05-18T09:13:37+00:00

My code builds an xml output from mysql dataset. Then I need to transform

  • 0

My code builds an xml output from mysql dataset. Then I need to transform it to HTML. I saved it in a php variable and tried to use it in transformToXML( $XML ) as parameter but it raises it expects an object here. How do I convert this xml output to an object to be used as a parameter here. Here is my code:

<?php

// i am using the resultset to build an XML DOM but you can do whatever you like with it !

   header("Content-type: text/xml");
   $conn = new mysqli("localhost", "babar", "k4541616", "spec", 3306);
   // one non-recursive db call to get the message tree !
   $result = $conn->query("call message_hier(1)");
   //--$result = $conn->query("call message_hier_all()");
   $xml = new DomDocument;
   $xpath = new DOMXpath($xml);
   $msgs = $xml->createElement("messages");
   $xml->appendChild($msgs);
   // loop and build the DOM
   while($row = $result->fetch_assoc()){
     $msg = $xml->createElement("message");
     foreach($row as $col => $val) $msg->setAttribute($col, $val); 

   if(is_null($row["parent_msg_id"])){
     $msgs->appendChild($msg);
   }
   else{
     $qry = sprintf("//*[@msg_id = '%d']", $row["parent_msg_id"]);
     $parent = $xpath->query($qry)->item(0);
     if(!is_null($parent)) $parent->appendChild($msg);
    } 
   }
   $result->close();
   $conn->close();
   $save = $xml->saveXML();//-> Here i save mxl in php var
   //echo $save;

   $xslt = new XSLTProcessor();
   $XSL = new DOMDocument();
   $XSL->load( 'msg.xsl');
   $xslt->importStylesheet( $XSL );
   header('Content-Type: application/xml');
   print $xslt->transformToXML($save); //->error: expects an object here, string given.

  ?>
  • 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-18T09:13:37+00:00Added an answer on May 18, 2026 at 9:13 am

    You will need to turn your XML string back into an object via DOMDocument::loadXML() before you can use it.

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

Sidebar

Related Questions

I need to know how to turn on Code Coverage when running TFS builds
I need a way to build C++ code from UML diagrams and vice versa.
I have written an Objective-C framework which builds some HTML code with NSMutableString which
Imagine this as the code from build.xml: <project name=test project> <target name=first> <echo>first</echo> </target>
Existing code is using an asp:repeater to build an HTML table. (emphasis on the
I'm trying to build up a library of reusable code to use from project
Are there any good code profilers/analyzers for Erlang? I need something that can build
Code: <html xmlns=http://www.w3.org/1999/xhtml> <head> <title>Unusual Array Lengths!</title> <script type=text/javascript> var arrayList = new Array();
I am using this code to make a KML file: Sub Create_KML() ' Builds
I am attempting to build a simple method that creates an XML file from

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.