OK so here is what i wanna do. I been researching for a while but i didnt find the answer maybe you guys could help me out a little.

I wanna create a xml table from a MySQL data base query using something like this:

$file= fopen("results.xml", "w");
 $_xml ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n";
 $_xml .="<site>\r\n";
 while ($row = mysql_fetch_array($result)) {
      if ($row["pageTitle"]) {
           $_xml .="\t<page title=\"" . $row["pageTitle"] . "\">\r\n";
           $_xml .="\t\t<file>" . $row["pageLink"] . "</file>\r\n";$_xml .="\t</page>\r\n"; 
     } 
     else {
       $_xml .="\t<page title=\"Nothing Returned\">\r\n";$_xml .="\t\t<file>none</file>\r\n";
       $_xml .="\t</page>\r\n"; 
     }
 }
 $_xml .="</site>";
 fwrite($file, $_xml);
 fclose($file);
 echo "XML has been written.  <a href=\"results.xml\">View the XML.</a>";

OK i get that to work and i have it styled with a nice XSL too but the problem is this.

I wanna

echo $_xml;

var on one of my web pages, but i cant.

I read that i need to change the --> header ("content-type: text/xml");
But i cant do that because i have other output on the page.
So if i put it on the top of the page, the page dosent display right (if anything at all),
and i cant put it right above the

echo $_xml;

because then i get a
Warning: Cannot modify header information

and then i read this:

$mosConfig_locale_debug = 0;
$mosConfig_locale_use_gettext = 0;
add these two lines in configuration.php

but i cant Find that file.

IS the there anyways around this???
Im dying here.

Recommended Answers

All 3 Replies

Use this piece of code inorder to identify your problem:

$var = simplexml_load_string($xml);
var_dump($var);

Good luck.

Well im not sure what you mean but i will try this. Any problems that i do have i think i know the cause, its just that i think that i might be doing it wrong. I will use this code the first chance i get and report back. But if there are any other suggestions, i wouldn't mind hearing them.

Thanx,
Silo45

OK im not sure i think this is right. I dont understand why i did this.

object(SimpleXMLElement)#1 (1) { ["item"]=> array(2) { [0]=> object(SimpleXMLElement)#2 (14) { ["sellers_id"]=> string(2) "10" ["item_name"]=> string(9) "test_item" ["description"]=> string(64) "This is a test to see whether this works... and this too. " ["tag"]=> string(5) "Array" ["picture"]=> string(18) "images/Cartoon.jpg" ["min_price"]=> string(4) " $50" ["avg_price"]=> string(5) " $123" ["pickup_or_delivery"]=> string(6) "pickup" ["increments"]=> string(4) " $10" ["length"]=> string(1) "7" ["current_bid"]=> object(SimpleXMLElement)#4 (0) { } ["current_buyer_id"]=> object(SimpleXMLElement)#5 (0) { } ["max_bid"]=> object(SimpleXMLElement)#6 (0) { } ["ttl"]=> object(SimpleXMLElement)#7 (0) { } } [1]=> object(SimpleXMLElement)#3 (14) { ["sellers_id"]=> string(2) "10" ["item_name"]=> string(5) "test2" ["description"]=> string(54) "this is the second test. I hope this works. " ["tag"]=> string(5) "Array" ["picture"]=> string(18) "images/default.jpg" ["min_price"]=> string(5) " $123" ["avg_price"]=> string(5) " $543" ["pickup_or_delivery"]=> string(8) "delivery" ["increments"]=> string(3) " $5" ["length"]=> string(1) "7" ["current_bid"]=> object(SimpleXMLElement)#8 (0) { } ["current_buyer_id"]=> object(SimpleXMLElement)#9 (0) { } ["max_bid"]=> object(SimpleXMLElement)#10 (0) { } ["ttl"]=> object(SimpleXMLElement)#11 (0) { } } } }

Anyways im still having problems, but hopefully i get though.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.