Bonjour,
J'essaye d'écrire du XHML via php. Je fais un
1 2 3 4 5 6 7 8 9 10 11
| require_once('WebWriter.php');
require_once('XHTMLWriter.php');
$w = new XHTMLFile('/home/slide/toto.xhml');
$a = array('toto','tata','titi');
$w -> open_head();
$w -> set_content_type('text/xml; charset="utf-8"');
$w -> close_head();
$w -> open_body();
$w -> write_list($a,false);
$w -> close_body();
unset($w) |
bien sur j'ai des classes (dérivées de XMLWriter) qui sont censées me faire ça
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| <?php
class WebDocument
{
protected $doc = null; // the document to write
public function __construct($uri)
{
if(is_file($uri))
{
unlink($uri);
}
else
{
touch($uri);
}
$this->doc = new XMLWriter();
$this->doc->openURI($uri);
$this->doc->setIndent("\t");
}
/** Function to open the head element */
public function open_head()
{
$this->doc->startElement('head');
}
public function set_content_type($content)
{
$this->doc->startElement('meta');
$this->doc->writeAttribute('http-equiv','Content-Type');
$this->doc->writeAttribute('content',$content);
$this->doc->endElement();
}
/** Fucntion to set the title of web document
* @param [String] Title
*/
public function set_title($title)
{
$xw->writeElement ('title', $title);
}
/** Function to close the head element */
public function close_head()
{
$this->doc->endElement();
}
public function open_body()
{
$this->doc->startElement('body');
}
/** Write a HTML list
* @param [Array] A php array, indiced or scalar */
public function write_list($array,$ordoned = false)
{
if($ordoned)
{
$this->doc->startElement('ol');
}
else
{
$this->doc->startElement('ul');
}
foreach($array as $value)
{
$this->doc->startElement('li');
$this->doc->text($value);
$this->doc->endElement();
}
$this->doc->endElement();
}
public function close_body()
{
$this->doc->endElement();
}
public function __destruct()
{
$this->doc->endDtd();
$this->doc->endElement();
}
}
?> |
et
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| <?php
class XHTMLFile extends WebDocument
{
/** Construct the wap file
* Stop a the <head> element
*@param [String] URL to wap file */
public function __construct($uri)
{
parent::__construct($uri);
$this->doc->startDocument('1.0','UTF-8');
$this->doc->startDtd('html','-//W3C//DTD XHTML 1.0 Strict//EN', 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd');
$this->doc->endDtd();
$this->doc->startElement ('html');
$this->doc->writeAttribute( 'xmlns', 'http://www.w3.org/1999/xhtml');
$this->doc->writeAttribute( 'xml:lang', 'en');
}
}
?> |
mais le pb c'est qu'à la fin, j'ai ça
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/xml; charset="utf-8""/>
</head>
<body>
<ul>
<li>toto</li>
<li>tata</li>
<li>titi</li>
</ul>
</body>
</html>
c'est donc quand j'écris les meta, il intérprete le " commen une entité
est ce qu'il y a moyen de lui dire de ne pas le faire ?
PS : est ce que c'est un bonne idée de faire des classes comme ça qui m'écrive du XHTML (j'en ai un autre pour du WML)
en disant ça je pense surtout à IE qui est génant (parfois
)
par exemple lorsqu'on lui précise la ligne
<?xml version="1.0" encoding="utf-8" ?>
il intérprete mal certains CSS (eh oui)
lesquels je m'en rappel plus mais c'était par rapport au centrage
Partager