lay
03-06-2009, 03:16 AM
<?php
function writeXML($xmlfile, $tablename)
{
$query= "SELECT * FROM $tablename";
$result = mysql_query($query);
$doc = new DOMDocument('1.0', 'UTF-8');
$root = $doc->createElement('TableName');
$doc->appendChild($root);
while ($row = mysql_fetch_assoc($result)) {
$root_child = $doc->createElement('Login');
$root->appendChild($root_child);
$root_attr1 = $doc->createAttribute('Id');
$root_child->appendChild($root_attr1);
$root_text = $doc->createTextNode($row['id']);
$root_attr1->appendChild($root_text);
$title = $doc->createElement( "Username" );
$title->appendChild(
$doc->createTextNode( $row['username'] )
);
$root_child->appendChild( $title );
$publisher = $doc->createElement( "Password" );
$publisher->appendChild(
$doc->createTextNode( $row['pwd'] )
);
$root_child->appendChild( $publisher );
$root->appendChild( $root_child );
}
//$myFile = "test.xml";
$fh = fopen($xmlfile, 'w') or die("can't open file");
fwrite($fh, $doc->saveXML());
}
?>
I have this function and i call it like this:
include_once("connection.php");
$link = openConnection();
$bd = SelectBD($link);
writeXML('sample.xml', 'userpwd');
It have the problem when the data in the database have the character special. The problems are in Firefox it display like this � and in IE it display like this :
The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
An invalid character was found in text content. Error processing resource 'file:///C:/Program Files/Apache Group/Apache2/ht...
<TableName><Login Id="1"><Username>titi</Username><Password>123456</Password></Login&...
if it don't have problem it must display like this :
<?xml version="1.0" encoding="UTF-8"?>
<TableName><Login Id="1"><Username>titi</Username><Password>123456</Password></Login><Login Id="2"><Username>éclajdkfjd</Username><Password>jjjjjjjjjjjjjh</Password>
</Login></TableName>
function writeXML($xmlfile, $tablename)
{
$query= "SELECT * FROM $tablename";
$result = mysql_query($query);
$doc = new DOMDocument('1.0', 'UTF-8');
$root = $doc->createElement('TableName');
$doc->appendChild($root);
while ($row = mysql_fetch_assoc($result)) {
$root_child = $doc->createElement('Login');
$root->appendChild($root_child);
$root_attr1 = $doc->createAttribute('Id');
$root_child->appendChild($root_attr1);
$root_text = $doc->createTextNode($row['id']);
$root_attr1->appendChild($root_text);
$title = $doc->createElement( "Username" );
$title->appendChild(
$doc->createTextNode( $row['username'] )
);
$root_child->appendChild( $title );
$publisher = $doc->createElement( "Password" );
$publisher->appendChild(
$doc->createTextNode( $row['pwd'] )
);
$root_child->appendChild( $publisher );
$root->appendChild( $root_child );
}
//$myFile = "test.xml";
$fh = fopen($xmlfile, 'w') or die("can't open file");
fwrite($fh, $doc->saveXML());
}
?>
I have this function and i call it like this:
include_once("connection.php");
$link = openConnection();
$bd = SelectBD($link);
writeXML('sample.xml', 'userpwd');
It have the problem when the data in the database have the character special. The problems are in Firefox it display like this � and in IE it display like this :
The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
An invalid character was found in text content. Error processing resource 'file:///C:/Program Files/Apache Group/Apache2/ht...
<TableName><Login Id="1"><Username>titi</Username><Password>123456</Password></Login&...
if it don't have problem it must display like this :
<?xml version="1.0" encoding="UTF-8"?>
<TableName><Login Id="1"><Username>titi</Username><Password>123456</Password></Login><Login Id="2"><Username>éclajdkfjd</Username><Password>jjjjjjjjjjjjjh</Password>
</Login></TableName>