示例#1
0
<?php

$xw = xmlwriter_open_uri('./a.xml');
xmlwriter_set_indent($xw, 1);
$res = xmlwriter_set_indent_string($xw, ' ');
xmlwriter_start_document($xw, '1.0', 'utf8');
// A first element
xmlwriter_start_element($xw, 'tag1');
// Attribute 'att1' for element 'tag1'
xmlwriter_start_attribute($xw, 'att1');
xmlwriter_text($xw, 'valueofatt1');
xmlwriter_end_attribute($xw);
xmlwriter_write_comment($xw, 'this is a comment.');
// Start a child element
xmlwriter_start_element($xw, 'tag11');
xmlwriter_text($xw, utf8_encode('This is a sample text, ä'));
xmlwriter_end_element($xw);
// tag11
xmlwriter_end_element($xw);
// tag1
// partial example
<?php

/* $Id$ */
$doc_dest = '001.xml';
$xw = xmlwriter_open_uri($doc_dest);
xmlwriter_start_document($xw, '1.0', 'UTF-8');
xmlwriter_start_element($xw, "tag1");
xmlwriter_start_comment($xw);
xmlwriter_text($xw, 'comment');
xmlwriter_end_comment($xw);
xmlwriter_write_comment($xw, "comment #2");
xmlwriter_end_document($xw);
// Force to write and empty the buffer
$output_bytes = xmlwriter_flush($xw, true);
echo file_get_contents($doc_dest);
unset($xw);
unlink('001.xml');
?>
===DONE===
示例#3
0
VERIFY(xmlwriter_write_element_ns($xml, "prefix", "name", "http://some.url/", 1337));
VERIFY(xmlwriter_start_element($xml, "node"));
VERIFY(xmlwriter_full_end_element($xml));
VERIFY(xmlwriter_end_element($xml));
VERIFY(xmlwriter_start_element($xml, "node"));
VERIFY(xmlwriter_start_cdata($xml));
VERIFY(xmlwriter_text($xml, "Raw text"));
VERIFY(xmlwriter_end_cdata($xml));
VERIFY(xmlwriter_end_element($xml));
VERIFY(xmlwriter_start_element($xml, "node"));
VERIFY(xmlwriter_write_cdata($xml, "More CDATA"));
VERIFY(xmlwriter_end_element($xml));
VERIFY(xmlwriter_start_comment($xml));
VERIFY(xmlwriter_text($xml, "Comments"));
VERIFY(xmlwriter_end_comment($xml));
VERIFY(xmlwriter_write_comment($xml, "More comments"));
VERIFY(xmlwriter_start_pi($xml, "lol"));
VERIFY(xmlwriter_end_pi($xml));
VERIFY(xmlwriter_write_pi($xml, "php", "print 'Hello world!';"));
VERIFY(xmlwriter_write_raw($xml, "<node>Raw XML</node>"));
VERIFY(xmlwriter_write_dtd($xml, "name", "publicID", "systemID", "subset"));
VERIFY(xmlwriter_start_dtd($xml, "name", "publicID", "systemID"));
VERIFY(xmlwriter_end_dtd($xml));
VERIFY(xmlwriter_start_dtd_element($xml, "name"));
VERIFY(xmlwriter_end_dtd_element($xml));
VERIFY(xmlwriter_write_dtd_element($xml, "name", "content"));
VERIFY(xmlwriter_start_dtd_attlist($xml, "name"));
VERIFY(xmlwriter_end_dtd_attlist($xml));
VERIFY(xmlwriter_write_dtd_attlist($xml, "name", "content"));
VERIFY(xmlwriter_start_dtd_entity($xml, "name", false));
VERIFY(xmlwriter_end_dtd_entity($xml));
 protected function get_xmldata($id = 0, $current_value)
 {
     $this->db =& $GLOBALS['phpgw']->db;
     $id = (int) $id;
     $sql = "SELECT * FROM fm_entity_1_11 WHERE id = {$id}";
     $this->db->query($sql, __LINE__, __FILE__);
     $anlegg = array();
     $TreeID = $this->type;
     $PeriodFrom = date('Ym');
     if ($current_value) {
         $PeriodTo = 209912;
     } else {
         $PeriodTo = '000000';
     }
     $memory = xmlwriter_open_memory();
     xmlwriter_set_indent($memory, true);
     xmlwriter_start_document($memory, '1.0', 'UTF-8');
     xmlwriter_start_element($memory, 'TreeListe');
     xmlwriter_write_attribute($memory, 'TreeID', $TreeID);
     xmlwriter_write_attribute($memory, 'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
     xmlwriter_write_attribute($memory, 'xsi:noNamespaceSchemaLocation', 'TreeListe.xsd');
     while ($this->db->next_record()) {
         xmlwriter_start_element($memory, 'Tree');
         xmlwriter_write_element($memory, 'ID', 'TJ');
         xmlwriter_write_element($memory, 'Verdi', substr($this->db->f('maalepunkt_id'), -8));
         xmlwriter_write_element($memory, 'Beskrivelse', $this->db->f('address'));
         xmlwriter_write_element($memory, 'Firma', 'BB');
         xmlwriter_write_element($memory, 'PeriodeFra', $PeriodFrom);
         xmlwriter_write_element($memory, 'PeriodeTil', $PeriodTo);
         xmlwriter_write_element($memory, 'Status', 'N');
         xmlwriter_start_element($memory, 'BegrepsLister');
         xmlwriter_start_element($memory, 'BegrepsListe');
         xmlwriter_write_attribute($memory, 'Prosent', 100);
         xmlwriter_start_element($memory, 'Begrep');
         xmlwriter_write_comment($memory, 'Firma');
         xmlwriter_write_element($memory, 'ID', 'A3');
         xmlwriter_write_element($memory, 'Verdi', 'BB');
         xmlwriter_end_element($memory);
         xmlwriter_start_element($memory, 'Begrep');
         xmlwriter_write_comment($memory, 'Art');
         xmlwriter_write_element($memory, 'ID', 'A0');
         xmlwriter_write_element($memory, 'Verdi', '12304121');
         xmlwriter_end_element($memory);
         xmlwriter_start_element($memory, 'Begrep');
         xmlwriter_write_comment($memory, 'Asvar');
         xmlwriter_write_element($memory, 'ID', 'C1');
         xmlwriter_write_element($memory, 'Verdi', 45);
         xmlwriter_end_element($memory);
         xmlwriter_start_element($memory, 'Begrep');
         xmlwriter_write_comment($memory, 'Tjeneste');
         xmlwriter_write_element($memory, 'ID', 'TJE');
         xmlwriter_write_element($memory, 'Verdi', '');
         xmlwriter_end_element($memory);
         xmlwriter_start_element($memory, 'Begrep');
         xmlwriter_write_comment($memory, 'Objekt');
         xmlwriter_write_element($memory, 'ID', 'F0');
         xmlwriter_write_element($memory, 'Verdi', $this->db->f('loc1'));
         xmlwriter_end_element($memory);
         xmlwriter_start_element($memory, 'Begrep');
         xmlwriter_write_comment($memory, 'Prosjekt');
         xmlwriter_write_element($memory, 'ID', 'B0');
         xmlwriter_write_element($memory, 'Verdi', '');
         xmlwriter_end_element($memory);
         xmlwriter_start_element($memory, 'Begrep');
         xmlwriter_write_comment($memory, 'Fagkode');
         xmlwriter_write_element($memory, 'ID', 'B1');
         xmlwriter_write_element($memory, 'Verdi', '999');
         xmlwriter_end_element($memory);
         xmlwriter_start_element($memory, 'Begrep');
         xmlwriter_write_comment($memory, 'AV');
         xmlwriter_write_element($memory, 'ID', 'AV');
         xmlwriter_write_element($memory, 'Verdi', '');
         xmlwriter_end_element($memory);
         xmlwriter_end_element($memory);
         xmlwriter_end_element($memory);
         xmlwriter_end_element($memory);
     }
     xmlwriter_end_element($memory);
     $xml = xmlwriter_output_memory($memory, true);
     if ($this->debug) {
         header('Content-type: text/xml');
         echo $xml;
         die;
     }
     return $xml;
 }
示例#5
0
文件: 009.php 项目: badlamer/hhvm
<?php

/* $Id$ */
/*
Libxml 2.6.24 and up adds a new line after a processing instruction (PI)
*/
$xw = xmlwriter_open_memory();
xmlwriter_set_indent($xw, TRUE);
xmlwriter_start_document($xw, NULL, "UTF-8");
xmlwriter_start_element($xw, 'root');
xmlwriter_write_attribute($xw, 'id', 'elem1');
xmlwriter_start_element($xw, 'elem1');
xmlwriter_write_attribute($xw, 'attr1', 'first');
xmlwriter_write_comment($xw, 'start PI');
xmlwriter_start_element($xw, 'pi');
xmlwriter_write_pi($xw, 'php', 'echo "hello world"; ');
xmlwriter_end_element($xw);
xmlwriter_start_element($xw, 'cdata');
xmlwriter_start_cdata($xw);
xmlwriter_text($xw, '<>&"');
xmlwriter_end_cdata($xw);
xmlwriter_end_element($xw);
xmlwriter_end_element($xw);
xmlwriter_end_element($xw);
xmlwriter_end_document($xw);
// Force to write and empty the buffer
$output = xmlwriter_flush($xw, true);
print $output;