Exemplo n.º 1
0
 /**
  * We want to check that we get the expected structure from
  * xmlwriter & an idea of how it works, once we have this
  * down we can start working on the actual methods needed
  * to authenticate.
  *
  */
 function testXMLWriterCanCreateOurNeededXML()
 {
     $xml = xmlwriter_open_memory();
     xmlwriter_start_element($xml, 'Authentication');
     xmlwriter_write_element($xml, 'client', 'blah');
     xmlwriter_write_element($xml, 'password', 'blah');
     xmlwriter_end_element($xml);
     $result = xmlwriter_output_memory($xml, true);
     $expected = '<Authentication><client>blah</client><password>blah</password></Authentication>';
     $this->assertContains('Authentication', $result);
     $this->assertXmlStringEqualsXmlString($expected, $result);
 }
Exemplo n.º 2
0
 public static function toXml($writer, $data, $node)
 {
     foreach ($data as $key => $value) {
         if (is_numeric($key)) {
             $key = $node;
         }
         if (is_array($value)) {
             xmlwriter_start_element($writer, $key);
             OC_OCS::toxml($writer, $value, $node);
             xmlwriter_end_element($writer);
         } else {
             xmlwriter_write_element($writer, $key, $value);
         }
     }
 }
Exemplo n.º 3
0
 /**
  * @brief Generate an RSS feed
  * @param string $link
  * @param string $content
  */
 public static function generaterss($link, $content)
 {
     $writer = xmlwriter_open_memory();
     xmlwriter_set_indent($writer, 4);
     xmlwriter_start_document($writer, '1.0', 'utf-8');
     xmlwriter_start_element($writer, 'rss');
     xmlwriter_write_attribute($writer, 'version', '2.0');
     xmlwriter_write_attribute($writer, 'xmlns:atom', 'http://www.w3.org/2005/Atom');
     xmlwriter_start_element($writer, 'channel');
     xmlwriter_write_element($writer, 'title', 'my ownCloud');
     xmlwriter_write_element($writer, 'language', 'en-us');
     xmlwriter_write_element($writer, 'link', $link);
     xmlwriter_write_element($writer, 'description', 'A personal ownCloud activities');
     xmlwriter_write_element($writer, 'pubDate', date('r'));
     xmlwriter_write_element($writer, 'lastBuildDate', date('r'));
     xmlwriter_start_element($writer, 'atom:link');
     xmlwriter_write_attribute($writer, 'href', $link);
     xmlwriter_write_attribute($writer, 'rel', 'self');
     xmlwriter_write_attribute($writer, 'type', 'application/rss+xml');
     xmlwriter_end_element($writer);
     // items
     for ($i = 0; $i < count($content); $i++) {
         xmlwriter_start_element($writer, 'item');
         if (isset($content[$i]['subject'])) {
             xmlwriter_write_element($writer, 'title', $content[$i]['subject']);
         }
         if (isset($content[$i]['link'])) {
             xmlwriter_write_element($writer, 'link', $content[$i]['link']);
         }
         if (isset($content[$i]['link'])) {
             xmlwriter_write_element($writer, 'guid', $content[$i]['link']);
         }
         if (isset($content[$i]['timestamp'])) {
             xmlwriter_write_element($writer, 'pubDate', date('r', $content[$i]['timestamp']));
         }
         if (isset($content[$i]['message'])) {
             xmlwriter_start_element($writer, 'description');
             xmlwriter_start_cdata($writer);
             xmlwriter_text($writer, $content[$i]['message']);
             xmlwriter_end_cdata($writer);
             xmlwriter_end_element($writer);
         }
         xmlwriter_end_element($writer);
     }
     xmlwriter_end_element($writer);
     xmlwriter_end_element($writer);
     xmlwriter_end_document($writer);
     $entry = xmlwriter_output_memory($writer);
     unset($writer);
     return $entry;
 }
<?php

/* $Id$ */
$xw = xmlwriter_open_memory();
xmlwriter_set_indent($xw, TRUE);
xmlwriter_set_indent_string($xw, '   ');
xmlwriter_start_document($xw, '1.0', "UTF-8");
xmlwriter_start_element($xw, 'root');
xmlwriter_start_element_ns($xw, 'ns1', 'child1', 'urn:ns1');
xmlwriter_write_attribute_ns($xw, 'ns1', 'att1', 'urn:ns1', '<>"\'&');
xmlwriter_write_element($xw, 'chars', "special characters: <>\"'&");
xmlwriter_end_element($xw);
xmlwriter_end_document($xw);
// Force to write and empty the buffer
$output = xmlwriter_flush($xw, true);
print $output;
Exemplo n.º 5
0
 /**
  * Take an array of any size, and make it into xml
  * @param xmlwriter	An xmlwriter instance
  * @param array			The array which is to be transformed
  * @param mixed			Either a string, or an array of elements defining element names for each level in the XML hierarchy
  *									 In the case of multiple lists of differently titled items at the same level, adding an array inside the array will allow for this to be constructed.
  * @param int				Internal use (the index of the child item in question - corresponds to the index in the second level array above)
  */
 public function toxml($writer, $data, $node, $childindex = 0)
 {
     $nodename = $node;
     if (is_array($node)) {
         $nodename = array_shift($node);
     }
     $childcount = -1;
     foreach ($data as $key => $value) {
         $childcount++;
         if (is_numeric($key)) {
             if (is_array($nodename)) {
                 $key = $nodename[$childindex];
             } else {
                 $key = $nodename;
             }
         }
         if (is_array($value)) {
             xmlwriter_start_element($writer, $key);
             $this->toxml($writer, $value, $node, $childcount);
             xmlwriter_end_element($writer);
         } else {
             xmlwriter_write_element($writer, $key, $value);
         }
     }
     if (is_array($node)) {
         array_unshift($node, $nodename);
     }
 }
 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;
 }
Exemplo n.º 7
0
 /**
  * Sets our 3DSecure request to confirm the transaction.
  *
  * @param string $pares
  * @param string $reference
  * @param string $method
  * @return SimpleXML
  * 
  */
 function set3DSecureAuthRequest($pares, $reference, $method = 'deposits')
 {
     if (is_null($pares) || empty($pares)) {
         throw new Zend_Exception('PaRes is not set');
     }
     if (strlen($reference) !== 16) {
         throw new Zend_Exception('Reference must be 16 characters long');
     }
     $xml = xmlwriter_open_memory();
     xmlwriter_start_element($xml, 'Request');
     $auth = $this->_handleAuth($method);
     xmlwriter_write_raw($xml, $auth);
     xmlwriter_start_element($xml, 'Transaction');
     xmlwriter_start_element($xml, 'HistoricTxn');
     xmlwriter_write_element($xml, 'reference', $reference);
     xmlwriter_start_element($xml, 'method');
     xmlwriter_write_attribute($xml, 'tx_status_u', 'accept');
     xmlwriter_write_raw($xml, 'threedsecure_authorization_request');
     xmlwriter_end_element($xml);
     xmlwriter_write_element($xml, 'pares_message', $pares);
     xmlwriter_end_element($xml);
     xmlwriter_end_element($xml);
     xmlwriter_end_element($xml);
     return xmlwriter_output_memory($xml, true);
 }
Exemplo n.º 8
0
    }
}
function VERIFY($x)
{
    VS($x, true);
}
$xml = xmlwriter_open_memory();
var_dump($xml);
VERIFY(xmlwriter_set_indent($xml, true));
VERIFY(xmlwriter_set_indent_string($xml, "  "));
VERIFY(xmlwriter_start_document($xml, "1.0", "utf-8"));
VERIFY(xmlwriter_start_element($xml, "node"));
VERIFY(xmlwriter_write_attribute($xml, "name", "value"));
VERIFY(xmlwriter_start_attribute($xml, "name2"));
VERIFY(xmlwriter_end_attribute($xml));
VERIFY(xmlwriter_write_element($xml, "subnode", "some text"));
VERIFY(xmlwriter_end_element($xml));
VERIFY(xmlwriter_start_element_ns($xml, "fb", "node", "http://www.facebook.com/"));
VERIFY(xmlwriter_write_attribute_ns($xml, "fb", "attr", "http://www.facebook.com/", "value"));
VERIFY(xmlwriter_start_attribute_ns($xml, "fb", "attr2", "http://www.facebook.com/"));
VERIFY(xmlwriter_end_attribute($xml));
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"));