示例#1
0
function main()
{
    $x = new XMLWriter();
    $x->openMemory();
    $x->setIndent(true);
    $x->startDocument('1.0');
    $x->startElementNS(null, 'startNullPrefix', null);
    $x->startElementNS('', 'startEmptyPrefix', null);
    $x->writeElementNS(null, 'writeNullPrefix', null);
    $x->writeElementNS('', 'writeEmptyPrefix', null);
    $x->endElement();
    $x->endElement();
    $x->endDocument();
    var_dump($x->outputMemory(true));
}
示例#2
0
 public function write(\XMLWriter $writer, \DateTimeZone $timezone, $stringTag)
 {
     if (strpos(static::XMLRPC_TYPE, '}') !== false) {
         list($ns, $tagName) = explode('}', static::XMLRPC_TYPE, 2);
         $ns = (string) substr($ns, 1);
         return $writer->writeElementNS('ex', $tagName, $ns, gmp_strval($this->value));
     }
     return $writer->writeElement(static::XMLRPC_TYPE, gmp_strval($this->value));
 }
示例#3
0
 public function write(\XMLWriter $writer, \DateTimeZone $timezone, $stringTag)
 {
     // PHP has serious issues with timezone handling.
     // As a workaround, we use format(), specifying a UNIX timestamp
     // as the format to use, which we then reinject in a new DateTime.
     $date = new \DateTime('@' . $this->value->format('U'), $timezone);
     if (strpos(static::XMLRPC_TYPE, '}') !== false) {
         list($ns, $tagName) = explode('}', static::XMLRPC_TYPE, 2);
         $ns = (string) substr($ns, 1);
         return $writer->writeElementNS('ex', $tagName, $ns, $date->format(static::XMLRPC_FORMAT));
     }
     return $writer->writeElement(static::XMLRPC_TYPE, $date->format(static::XMLRPC_FORMAT));
 }
 /**
  * Link AssetDeliveryPolicy to Asset
  *
  * @param Models\Asset|string      $asset      Asset to link a AssetDeliveryPolicy or
  * Asset id
  *
  * @param Models\AssetDeliveryPolicy|string $policy DeliveryPolicy to link or
  * DeliveryPolicy id
  *
  * @return void
  */
 public function linkDeliveryPolicyToAsset($asset, $policy)
 {
     $assetId = Utilities::getEntityId($asset, 'WindowsAzure\\MediaServices\\Models\\Asset');
     $assetId = urlencode($assetId);
     $policyId = Utilities::getEntityId($policy, 'WindowsAzure\\MediaServices\\Models\\AssetDeliveryPolicy');
     $policyId = urlencode($policyId);
     $contentWriter = new \XMLWriter();
     $contentWriter->openMemory();
     $contentWriter->writeElementNS('data', 'uri', Resources::DS_XML_NAMESPACE, $this->getUri() . "AssetDeliveryPolicies('{$policyId}')");
     $method = Resources::HTTP_POST;
     $path = "Assets('{$assetId}')/\$links/DeliveryPolicies";
     $headers = array(Resources::CONTENT_TYPE => Resources::XML_CONTENT_TYPE);
     $postParams = array();
     $queryParams = array();
     $statusCode = Resources::STATUS_NO_CONTENT;
     $body = $contentWriter->outputMemory();
     $this->send($method, $headers, $postParams, $queryParams, $path, $statusCode, $body);
 }
示例#5
0
<?php

$xw = xmlwriter_open_memory();
xmlwriter_set_indent($xw, true);
xmlwriter_start_document($xw);
xmlwriter_start_element_ns($xw, 'test', 'test', 'urn:x-test:');
xmlwriter_write_element_ns($xw, 'test', 'foo', null, '');
xmlwriter_write_element_ns($xw, null, 'bar', 'urn:x-test:', '');
xmlwriter_write_element_ns($xw, null, 'bar', '', '');
xmlwriter_end_element($xw);
xmlwriter_end_document($xw);
print xmlwriter_flush($xw, true);
print "\n";
$xw = new XMLWriter();
$xw->openMemory();
$xw->setIndent(true);
$xw->startDocument();
$xw->startElementNS('test', 'test', 'urn:x-test:');
$xw->writeElementNS('test', 'foo', null, '');
$xw->writeElementNS(null, 'bar', 'urn:x-test:', '');
$xw->writeElementNS(null, 'bar', '', '');
$xw->endElement();
$xw->endDocument();
print $xw->flush(true);
示例#6
0
/**
 * Construct the catalog entry
 *
 * @param XmlWriter $xml XML stream to write to
 * @param array $data data-blob of i18n and config variables
 * @param array $dataset array of the dataset identifiers
 */
function writeCatalog(XMLWriter $xml, array $data, array $dataset)
{
    $xml->startElementNS('rdf', 'Description', null);
    $xml->writeAttributeNS('rdf', 'about', null, $data['config']['uri'] . '#catalog');
    $xml->startElementNS('rdf', 'type', null);
    $xml->writeAttributeNS('rdf', 'resource', null, 'http://www.w3.org/ns/dcat#Catalog');
    $xml->endElement();
    $xml->startElementNS('dcterms', 'license', null);
    $xml->writeAttributeNS('rdf', 'resource', null, $data['config']['catalog-license']);
    $xml->endElement();
    $xml->startElementNS('dcat', 'themeTaxonomy', null);
    $xml->writeAttributeNS('rdf', 'resource', null, 'http://eurovoc.europa.eu/');
    $xml->endElement();
    $xml->writeElementNS('foaf', 'homepage', null, $data['config']['catalog-homepage']);
    $xml->startElementNS('dcterms', 'modified', null);
    $xml->writeAttributeNS('rdf', 'datatype', null, 'http://www.w3.org/2001/XMLSchema#date');
    $xml->text(date('Y-m-d'));
    $xml->endElement();
    $xml->startElementNS('dcterms', 'issued', null);
    $xml->writeAttributeNS('rdf', 'datatype', null, 'http://www.w3.org/2001/XMLSchema#date');
    $xml->text($data['config']['catalog-issued']);
    $xml->endElement();
    $xml->startElementNS('dcterms', 'publisher', null);
    $xml->writeAttributeNS('rdf', 'nodeID', null, $data['ids']['publisher']);
    $xml->endElement();
    // add language, title and description in each language
    writeCatalogI18n($xml, $data);
    // add datasets
    foreach ($dataset as $key => $value) {
        $xml->startElementNS('dcat', 'dataset', null);
        $xml->writeAttributeNS('rdf', 'resource', null, $value);
        $xml->endElement();
    }
    $xml->endElement();
}
示例#7
0
文件: Nil.php 项目: fpoirotte/xrl
 public function write(\XMLWriter $writer, \DateTimeZone $timezone, $stringTag)
 {
     return $writer->writeElementNS('ex', 'nil', 'http://ws.apache.org/xmlrpc/namespaces/extensions');
 }
<?php

/* $Id$ */
$doc_dest = '001.xml';
$xw = new XMLWriter();
$xw->openUri($doc_dest);
$xw->startDtd('foo', NULL, 'urn:bar');
$xw->endDtd();
$xw->startElement('foo');
$xw->writeElementNS('foo', 'bar', 'urn:foo', 'dummy content');
$xw->endElement();
// Force to write and empty the buffer
$output_bytes = $xw->flush(true);
echo file_get_contents($doc_dest);
unset($xw);
unlink('001.xml');
示例#9
0
 /**
  * @param GraphBuilder $graph the graph visitor to use for building the output data.
  * @return string GraphML string.
  */
 public function format(GraphBuilder $graph)
 {
     $xml = new \XMLWriter();
     $xml->openMemory();
     $xml->startDocument('1.0');
     $xml->setIndent(4);
     $dataFunctions = ['graphml_resources' => ['for' => 'graphml', 'yfiles.type' => 'resources'], 'graph_description' => ['for' => 'graph', 'attr.name' => 'Description', 'attr.type' => 'string'], 'node_url' => ['for' => 'node', 'attr.name' => 'url', 'attr.type' => 'string'], 'node_description' => ['for' => 'node', 'attr.name' => 'description', 'attr.type' => 'string'], 'node_graphics' => ['for' => 'node', 'yfiles.type' => 'nodegraphics'], 'edge_url' => ['for' => 'edge', 'attr.name' => 'url', 'attr.type' => 'string'], 'edge_description' => ['for' => 'edge', 'attr.name' => 'description', 'attr.type' => 'string'], 'edge_graphics' => ['for' => 'edge', 'yfiles.type' => 'edgegraphics']];
     $xml->startElement('graphml');
     $xml->writeAttribute('xmlns', 'http://graphml.graphdrawing.org/xmlns');
     $xml->writeAttribute('xmlns:java', 'http://www.yworks.com/xml/yfiles-common/1.0/java');
     $xml->writeAttribute('xmlns:sys', 'http://www.yworks.com/xml/yfiles-common/markup/primitives/2.0');
     $xml->writeAttribute('xmlns:x', 'http://www.yworks.com/xml/yfiles-common/markup/2.0');
     $xml->writeAttribute('xmlns:y', 'http://www.yworks.com/xml/graphml');
     $xml->writeAttribute('xmlns:yed', 'http://www.yworks.com/xml/yed/3');
     $xml->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
     $xml->writeAttribute('xsi:schemaLocation', 'http://graphml.graphdrawing.org/xmlns ' . 'http://graphml.graphdrawing.org/xmlns/1.0/graphml.xs ' . 'http://www.yworks.com/xml/schema/graphml/1.1/ygraphml.xsd');
     // Data functions
     foreach ($dataFunctions as $key_id => $key_data) {
         $xml->startElement('key');
         $xml->writeAttribute('id', $key_id);
         foreach ($key_data as $attr_name => $attr_val) {
             $xml->writeAttribute($attr_name, $attr_val);
         }
         $xml->endElement();
         // key
     }
     // Graph
     $xml->startElement('graph');
     $xml->writeAttribute('id', 'G');
     $xml->writeAttribute('edgedefault', 'directed');
     $xml->startElement('data');
     $xml->writeAttribute('key', 'graph_description');
     $xml->endElement();
     // data
     // Nodes
     foreach ($graph->nodes as $node_key => $node) {
         $xml->startElement('node');
         $xml->writeAttribute('id', $node_key);
         // Data
         $xml->startElement('data');
         $xml->writeAttribute('key', 'node_url');
         $xml->text('file://' . $node['file']);
         $xml->endElement();
         // data (url)
         $xml->startElement('data');
         $xml->writeAttribute('key', 'node_description');
         // TODO: write class comment
         $xml->endElement();
         // data (description)
         $xml->startElement('data');
         $xml->writeAttribute('key', 'node_graphics');
         $xml->startElementNS('y', 'UMLClassNode', null);
         // Geometry
         $xml->startElementNS('y', 'Geometry', null);
         $xml->writeAttribute('width', '173.0');
         $xml->writeAttribute('height', '27.0');
         $xml->writeAttribute('x', '0');
         $xml->writeAttribute('y', '0');
         $xml->endElement();
         // Fill
         $xml->startElementNS('y', 'Fill', null);
         $xml->writeAttribute('color', '#FFC000');
         $xml->writeAttribute('transparent', 'false');
         $xml->endElement();
         // Border
         $xml->startElementNS('y', 'BorderStyle', null);
         $xml->writeAttribute('color', '#000000');
         $xml->writeAttribute('type', 'line');
         $xml->writeAttribute('width', '1.0');
         $xml->endElement();
         // Label
         $xml->startElementNS('y', 'NodeLabel', null);
         $xml->writeAttribute('alignment', 'center');
         $xml->writeAttribute('autoSizePolicy', 'content');
         $xml->writeAttribute('fontFamily', 'Dialog');
         $xml->writeAttribute('fontSize', '13');
         $xml->writeAttribute('fontStyle', 'bold');
         $xml->writeAttribute('hasBackgroundColor', 'false');
         $xml->writeAttribute('hasLineColor', 'false');
         $xml->writeAttribute('modelName', 'custom');
         $xml->writeAttribute('textColor', '#000000');
         $xml->writeAttribute('visible', 'true');
         $xml->writeAttribute('x', '23.794677734375');
         // Necessary?
         $xml->writeAttribute('y', '3.0');
         // Necessary?
         $xml->writeAttribute('width', '64.41064453125');
         // Necessary?
         $xml->writeAttribute('height', '19.310546875');
         // Necessary?
         // Label text
         $xml->text($node['name']);
         $xml->startElementNS('y', 'LabelModel', null);
         $xml->startElementNS('y', 'SmartNodeLabelModel', null);
         $xml->writeAttribute('distance', '4.0');
         $xml->endElement();
         // y:SmartModeLabelModel
         $xml->endElement();
         // y:LabelModel
         $xml->startElementNS('y', 'ModelParameter', null);
         $xml->startElementNS('y', 'SmartNodeLabelModelParameter', null);
         $xml->writeAttribute('labelRatioX', '0.0');
         $xml->writeAttribute('labelRatioY', '0.0');
         $xml->writeAttribute('nodeRatioX', '0.0');
         // Necessary?
         $xml->writeAttribute('nodeRatioY', '-0.03703090122767855');
         // Necessary?
         $xml->writeAttribute('offsetX', '0.0');
         $xml->writeAttribute('offsetY', '0.0');
         $xml->writeAttribute('upX', '0.0');
         $xml->writeAttribute('upY', '-1.0');
         $xml->endElement();
         // y:SmartNodeLabelModelParameter
         $xml->endElement();
         // y:ModelParameter
         $xml->endElement();
         // y:NodeLabel
         $xml->startElementNS('y', 'UML', null);
         $xml->writeAttribute('clipContent', 'true');
         $xml->writeAttribute('constraint', '');
         $xml->writeAttribute('omitDetails', 'false');
         $xml->writeAttribute('stereotype', $node['stereotype']);
         $xml->writeAttribute('use3DEffect', 'true');
         // TODO: uml attribs
         $xml->writeElementNS('y', 'AttributeLabel', null);
         // TODO: uml operations
         $xml->writeElementNS('y', 'MethodLabel', null);
         $xml->endElement();
         // y:UML
         $xml->endElement();
         // y:UMLClassNode
         $xml->endElement();
         // data
         $xml->endElement();
         // node
     }
     // Edges
     foreach ($graph->edges as $edge) {
         $xml->startElement('edge');
         $xml->writeAttribute('source', $edge['source']);
         $xml->writeAttribute('target', $edge['target']);
         $xml->startElement('data');
         $xml->writeAttribute('key', 'edge_url');
         $xml->endElement();
         // data
         $xml->startElement('data');
         $xml->writeAttribute('key', 'edge_description');
         $xml->endElement();
         // data
         $xml->startElement('data');
         $xml->writeAttribute('key', 'edge_graphics');
         $xml->startElementNS('y', 'PolyLineEdge', null);
         // Path
         $xml->startElementNS('y', 'Path', null);
         $xml->writeAttribute('sx', '0.0');
         $xml->writeAttribute('sy', '0.0');
         $xml->writeAttribute('tx', '0.0');
         $xml->writeAttribute('ty', '0.0');
         $xml->endElement();
         // y:Path
         // Line Style
         $xml->startElementNS('y', 'LineStyle', null);
         $xml->writeAttribute('color', '#000000');
         if ($edge['type'] === EdgeType::GENERALIZATION) {
             $xml->writeAttribute('type', 'line');
         } elseif ($edge['type'] === EdgeType::REALIZATION || $edge['type'] === EdgeType::DEPENDENCY) {
             $xml->writeAttribute('type', 'dashed');
         }
         $xml->writeAttribute('width', '1.0');
         $xml->endElement();
         // y:LineStyle
         // Arrow
         $xml->startElementNS('y', 'Arrows', null);
         $xml->writeAttribute('source', 'none');
         if ($edge['type'] === EdgeType::GENERALIZATION || $edge['type'] === EdgeType::REALIZATION) {
             $xml->writeAttribute('target', 'white_delta');
         } elseif ($edge['type'] === EdgeType::DEPENDENCY) {
             $xml->writeAttribute('target', 'plain');
         }
         $xml->endElement();
         // y:Arrows
         // Label
         if ($edge['label']) {
             $xml->startElementNS('y', 'EdgeLabel', null);
             $xml->writeAttribute('alignment', 'center');
             $xml->writeAttribute('configuration', 'AutoFlippingLabel');
             $xml->writeAttribute('distance', '2.0');
             $xml->writeAttribute('fontFamily', 'Dialog');
             $xml->writeAttribute('fontSize', '12');
             $xml->writeAttribute('fontStyle', 'plain');
             $xml->writeAttribute('hasBackgroundColor', 'false');
             $xml->writeAttribute('hasLineColor', 'false');
             $xml->writeAttribute('modelName', 'custom');
             $xml->writeAttribute('preferredPlacement', 'anywhere');
             $xml->writeAttribute('ratio', '0.5');
             $xml->writeAttribute('textColor', '#000000');
             $xml->writeAttribute('visible', 'true');
             $xml->writeAttribute('width', '23.154296875');
             // Necessary?
             $xml->writeAttribute('height', '18.1328125');
             // Necessary?
             $xml->writeAttribute('x', '-10.371107530854715');
             // Necessary?
             $xml->writeAttribute('y', '-63.07865606857578');
             // Necessary?
             $xml->text($edge['label']);
             // Label
             $xml->startElementNS('y', 'LabelModel', null);
             $xml->startElementNS('y', 'SmartEdgeLabelModel', null);
             $xml->writeAttribute('autoRotationEnabled', 'false');
             $xml->writeAttribute('defaultAngle', '0.0');
             $xml->writeAttribute('defaultDistance', '10.0');
             $xml->endElement();
             // y:SmartEdgeLabelModel
             $xml->endElement();
             // y:LabelModel
             $xml->startElementNS('y', 'ModelParameter', null);
             $xml->startElementNS('y', 'SmartEdgeLabelModelParameter', null);
             $xml->writeAttribute('angle', '0.0');
             $xml->writeAttribute('distance', '30.0');
             $xml->writeAttribute('distanceToCenter', 'true');
             $xml->writeAttribute('position', 'right');
             $xml->writeAttribute('ratio', '0.5');
             $xml->writeAttribute('segment', '0');
             $xml->endElement();
             // y:SmartEdgeLabelModelParameter
             $xml->endElement();
             // y:ModelParameter
             $xml->startElementNS('y', 'PreferredPlacementDescriptor', null);
             $xml->writeAttribute('angle', '0.0');
             $xml->writeAttribute('angleOffsetOnRightSide', '0');
             $xml->writeAttribute('angleReference', 'absolute');
             $xml->writeAttribute('angleRotationOnRightSide', 'co');
             $xml->writeAttribute('distance', '-1.0');
             $xml->writeAttribute('frozen', 'true');
             $xml->writeAttribute('placement', 'anywhere');
             $xml->writeAttribute('side', 'anywhere');
             $xml->writeAttribute('sideReference', 'relative_to_edge_flow');
             $xml->endElement();
             // y:PreferredPlacementDescriptor
             $xml->endElement();
             // y:EdgeLabel
         }
         // Band Style
         $xml->startElementNS('y', 'BandStyle', null);
         $xml->writeAttribute('smoothed', 'false');
         $xml->endElement();
         // y:BandStyle
         $xml->endElement();
         // y:PolyLineEdge
         $xml->endElement();
         // data
         $xml->endElement();
         // edge
     }
     $xml->endElement();
     // graph
     $xml->startElement('data');
     $xml->writeAttribute('key', 'graphml_resources');
     $xml->writeElementNS('y', 'Resources', null);
     $xml->endElement();
     // data
     $xml->endElement();
     // graphml
     $xml->endDocument();
     return $xml->outputMemory(false);
 }
示例#10
0
 /**
  * @param string $prefix
  * @param string $name
  * @param string $uri
  * @param null|string $content
  * @return bool
  */
 public function writeElementNS($prefix, $name, $uri = null, $content = null)
 {
     if (!$this->hasNSPrefix($prefix)) {
         $this->nsArray[$prefix] = $uri;
     }
     return parent::writeElementNS($prefix, $name, $uri, $content);
 }