<?php const N = "test.xml"; $xmlw = new XMLWriter(N); $xmlw->openURI(N); $xmlw->startDTD("xml"); $xmlw->endDTD(); $xmlw->setIndent(1); for ($i = 0; $i < 5; $i++) { $xmlw->startElement("user"); $xmlw->startElement("name"); $xmlw->text(rand(100, 900)); $xmlw->endElement(); $xmlw->startElement("password"); $xmlw->text(md5(uniqid())); $xmlw->endElement(); $xmlw->endElement(); } echo $xmlw->outputMemory();
public function html() { $uri = sprintf("http://%s/api/soap", $_SERVER['HTTP_HOST']); $html = new XMLWriter(); $html->openMemory(); $html->setIndent(TRUE); $html->startDTD('html', '-//W3C//DTD XHTML 1.0 Strict//EN', 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'); // standards compliant $html->endDTD(); $html->startElement('html'); $html->writeAttribute('xmlns', 'http://www.w3.org/1999/xhtml'); $html->startElement('head'); $html->writeElement('title', sprintf('%s Soap Definition', $this->name)); $html->endElement(); //head $html->startElement('body'); $html->writeElement('h1', sprintf('%s Soap Definition', $this->name)); $html->startElement('p'); $html->startElement('a'); $html->writeAttribute('href', "{$uri}/?wsdl"); $html->text('WSDL'); $html->endElement(); //p $html->endElement(); //p foreach ($this->oper as $o) { $html->writeElement('h2', "{$o} ("); $html->startElement('p'); foreach ($this->msgs[$o] as $p) { $html->startElement('blockquote'); $html->writeElement('code', $p->name); $html->writeElement('i', 'as'); $html->writeElement('i', $p->type); $html->endElement(); } $html->text(') {'); $html->writeElement('br'); $html->startElement('blockquote'); $html->text(' ...'); $html->writeElement('br'); $html->writeElement('b', $this->rets[$o]->name); $html->writeElement('i', 'as'); $html->writeElement('i', $this->rets[$o]->type); $html->endElement(); $html->text('}'); $html->endElement(); //p } $html->writeElement('style', ' code { color: blue; } '); $html->endElement(); //body $html->endElement(); //html header('Content-type: application/xhtml+xml; charset=UTF-8'); echo $html->outputMemory(TRUE); }