当前位置: 首页>>代码示例>>PHP>>正文


PHP XML_Util::attributesToString方法代码示例

本文整理汇总了PHP中XML_Util::attributesToString方法的典型用法代码示例。如果您正苦于以下问题:PHP XML_Util::attributesToString方法的具体用法?PHP XML_Util::attributesToString怎么用?PHP XML_Util::attributesToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在XML_Util的用法示例。


在下文中一共展示了XML_Util::attributesToString方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: toString

 /**
  * Returns a formatted string of the object
  * @param    object  $obj    Container object to be output as string
  * @access   public
  * @return   string
  */
 function toString(&$obj)
 {
     $indent = '';
     if (!$obj->isRoot()) {
         // no indent for root
         $this->_deep++;
         $indent = str_repeat($this->options['indent'], $this->_deep);
     } else {
         // Initialize string with xml declaration
         $string = '';
         if ($this->options['addDecl']) {
             $string .= XML_Util::getXMLDeclaration($this->options['version'], $this->options['encoding']);
             $string .= $this->options['linebreak'];
         }
         if (!empty($this->options['name'])) {
             $string .= '<' . $this->options['name'] . '>' . $this->options['linebreak'];
             $this->_deep++;
             $indent = str_repeat($this->options['indent'], $this->_deep);
         }
     }
     if (!isset($string)) {
         $string = '';
     }
     switch ($obj->type) {
         case 'directive':
             $attributes = $this->options['useAttr'] ? $obj->attributes : array();
             $string .= $indent . XML_Util::createTag($obj->name, $attributes, $obj->content, null, $this->options['useCData'] ? XML_UTIL_CDATA_SECTION : XML_UTIL_REPLACE_ENTITIES);
             $string .= $this->options['linebreak'];
             break;
         case 'comment':
             $string .= $indent . '<!-- ' . $obj->content . ' -->';
             $string .= $this->options['linebreak'];
             break;
         case 'section':
             if (!$obj->isRoot()) {
                 $string = $indent . '<' . $obj->name;
                 $string .= $this->options['useAttr'] ? XML_Util::attributesToString($obj->attributes) : '';
             }
             if ($children = count($obj->children)) {
                 if (!$obj->isRoot()) {
                     $string .= '>' . $this->options['linebreak'];
                 }
                 for ($i = 0; $i < $children; $i++) {
                     $string .= $this->toString($obj->getChild($i));
                 }
             }
             if (!$obj->isRoot()) {
                 if ($children) {
                     $string .= $indent . '</' . $obj->name . '>' . $this->options['linebreak'];
                 } else {
                     $string .= '/>' . $this->options['linebreak'];
                 }
             } else {
                 if (!empty($this->options['name'])) {
                     $string .= '</' . $this->options['name'] . '>' . $this->options['linebreak'];
                 }
             }
             break;
         default:
             $string = '';
     }
     if (!$obj->isRoot()) {
         $this->_deep--;
     }
     return $string;
 }
开发者ID:5haman,项目名称:knowledgetree,代码行数:72,代码来源:XML.php

示例2: createStartElement

 /**
  * create a start element
  *
  * <code>
  * require_once 'XML/Util.php';
  * 
  * // create an XML start element:
  * $tag = XML_Util::createStartElement("myNs:myTag", array("foo" => "bar") ,"http://www.w3c.org/myNs#");
  * </code>
  *
  * @access   public
  * @static
  * @param    string  $qname             qualified tagname (including namespace)
  * @param    array   $attributes        array containg attributes
  * @param    string  $namespaceUri      URI of the namespace
  * @param    boolean $multiline         whether to create a multiline tag where each attribute gets written to a single line
  * @param    string  $indent            string used to indent attributes (_auto indents attributes so they start at the same column)
  * @param    string  $linebreak         string used for linebreaks
  * @return   string  $string            XML start element
  * @see      XML_Util::createEndElement(), XML_Util::createTag()
  */
 function createStartElement($qname, $attributes = array(), $namespaceUri = null, $multiline = false, $indent = '_auto', $linebreak = "\n")
 {
     // if no attributes hav been set, use empty attributes
     if (!isset($attributes) || !is_array($attributes)) {
         $attributes = array();
     }
     if ($namespaceUri != null) {
         $parts = XML_Util::splitQualifiedName($qname);
     }
     // check for multiline attributes
     if ($multiline === true) {
         if ($indent === "_auto") {
             $indent = str_repeat(" ", strlen($qname) + 2);
         }
     }
     if ($namespaceUri != null) {
         // is a namespace given
         if (isset($parts["namespace"]) && !empty($parts["namespace"])) {
             $attributes["xmlns:" . $parts["namespace"]] = $namespaceUri;
         } else {
             // define this Uri as the default namespace
             $attributes["xmlns"] = $namespaceUri;
         }
     }
     // create attribute list
     $attList = XML_Util::attributesToString($attributes, true, $multiline, $indent, $linebreak);
     $element = sprintf("<%s%s>", $qname, $attList);
     return $element;
 }
开发者ID:prometheus-ev,项目名称:promdilps,代码行数:50,代码来源:v2.php

示例3: array

print "</pre>";
print "\n<br><br>\n";
/**
 * creating an attribute string
 */
$att = array("foo" => "bar", "argh" => "tomato");
print "converting array to string:<br>\n";
print XML_Util::attributesToString($att);
print "\n<br><br>\n";
/**
 * creating an attribute string with linebreaks
 */
$att = array("foo" => "bar", "argh" => "tomato");
print "converting array to string (including line breaks):<br>\n";
print "<pre>";
print XML_Util::attributesToString($att, true, true);
print "</pre>";
print "\n<br><br>\n";
/**
 * splitting a qualified tag name
 */
print "splitting qualified tag name:<br>\n";
print "<pre>";
print_r(XML_Util::splitQualifiedName("xslt:stylesheet"));
print "</pre>";
print "\n<br>\n";
/**
 * splitting a qualified tag name (no namespace)
 */
print "splitting qualified tag name (no namespace):<br>\n";
print "<pre>";
开发者ID:bantudevelopment,项目名称:polysmis,代码行数:31,代码来源:example.php

示例4: _createImage

 /**
  * @param  string
  * @param  integer
  * @return string
  * @access private
  */
 function _createImage($word, $baseline)
 {
     $font = isset($this->_gtextAttributes['font']) ? $this->_gtextAttributes['font'] : 'arial.ttf';
     $fh = isset($this->_gtextAttributes['fontsize']) ? $this->_gtextAttributes['fontsize'] : 12;
     $bgcolor = isset($this->_gtextAttributes['bgcolor']) ? $this->_gtextAttributes['bgcolor'] : '#ffffff';
     $fgcolor = isset($this->_gtextAttributes['fgcolor']) ? $this->_gtextAttributes['fgcolor'] : '#ffffff';
     $antialias = isset($this->_gtextAttributes['antialias']) ? $this->_gtextAttributes['antialias'] : 'yes';
     $transparency = isset($this->_gtextAttributes['transparency']) ? $this->_gtextAttributes['transparency'] : 'yes';
     $cacheable = isset($this->_gtextAttributes['cacheable']) ? $this->_gtextAttributes['cacheable'] : 'yes';
     $spacing = isset($this->_gtextAttributes['spacing']) ? $this->_gtextAttributes['spacing'] : 2;
     $border = isset($this->_gtextAttributes['border']) ? $this->_gtextAttributes['border'] : 0;
     $bordercolor = isset($this->_gtextAttributes['bordercolor']) ? $this->_gtextAttributes['bordercolor'] : '#ff0000';
     /* The cache name is derived from all attributes and cdata.
      * This is very conserative and may create to many cachefiles,
      * but better to err on the safe side.
      */
     $cachefile = md5(XML_Util::attributesToString($this->_gtextAttributes) . ':' . $word) . '.png';
     $cacheDir = $_SERVER['DOCUMENT_ROOT'] . PEAR_XML_TRANSFORMER_IMAGE_cacheDir;
     $cacheName = "{$cacheDir}/{$cachefile}";
     $cacheURL = PEAR_XML_TRANSFORMER_IMAGE_cacheDir . "/{$cachefile}";
     if (!is_dir($cacheDir)) {
         mkdir($cacheDir, 01777);
     }
     /* Don't do the same work twice. */
     if (file_exists($cacheName) && $cacheable != 'no') {
         return $cacheURL;
     }
     $r = ImageTTFBBox($fh, 0, $font, $word);
     $w = max(1 / 10 * $fh, abs($r[2] - $r[0]));
     $h = max(1, abs($r[7] - $r[1]));
     $x = $r[0];
     $y = $baseline;
     $www = $w + 2 * ($spacing + $border);
     $hhh = $fh + 2 * ($spacing + $border);
     $im = ImageCreate($www, $hhh);
     list($r, $g, $b) = $this->_colorString($bgcolor);
     $bg = ImageColorAllocate($im, $r, $g, $b);
     if ($transparency != 'no') {
         ImageColorTransparent($im, $bg);
     }
     list($r, $g, $b) = $this->_colorString($fgcolor);
     $fg = ImageColorAllocate($im, $r, $g, $b);
     if ($antialias == 'no') {
         $fg = -$fg;
     }
     list($r, $g, $b) = $this->_colorString($bordercolor);
     $bo = ImageColorAllocate($im, $r, $g, $b);
     ImageFilledRectangle($im, 0, 0, $www, $hhh, $bg);
     if ($border > 0) {
         for ($i = $border; $i >= 0; $i--) {
             $x1 = $y1 = $i;
             $x2 = $www - $i - 1;
             $y2 = $hhh - $i - 1;
             ImageRectangle($im, $x1, $y1, $x2, $y2, $bo);
         }
     }
     ImageTTFText($im, $fh, 0, -$x + $spacing + $border, $hhh - (2 + $y + $spacing + $border), $fg, $font, $word);
     ImagePNG($im, $cacheName);
     ImageDestroy($im);
     return $cacheURL;
 }
开发者ID:Esleelkartea,项目名称:kz-adeada-talleres-electricos-,代码行数:67,代码来源:Image.php

示例5: end_random

 /**
  * @param  string
  * @return string
  * @access public
  */
 function end_random($cdata)
 {
     srand((double) microtime() * 1000000);
     $keys = array_keys($this->_anchorDatabase);
     $pos = rand(0, count($keys) - 1);
     $name = $keys[$pos];
     return sprintf('<a %s>%s</a>', XML_Util::attributesToString($this->_anchorDatabase[$name]), $cdata);
 }
开发者ID:Esleelkartea,项目名称:kz-adeada-talleres-electricos-,代码行数:13,代码来源:Anchor.php

示例6: startElement

 /**
  * Wrapper for startElement handler.
  *
  * @param  string
  * @param  array
  * @return string
  * @access public
  */
 function startElement($element, $attributes)
 {
     $do = 'start_' . $element;
     if (method_exists($this, $do)) {
         return $this->{$do}($attributes);
     }
     return sprintf("<%s%s>", $element, XML_Util::attributesToString($attributes));
 }
开发者ID:GeekyNinja,项目名称:LifesavingCAD,代码行数:16,代码来源:Namespace.php

示例7: toString

 public function toString(__ConfigurationComponent &$configuration_component)
 {
     $indent = '';
     if (!$configuration_component->isRoot()) {
         // no indent for root
         $this->_deep++;
         $indent = str_repeat($this->options['indent'], $this->_deep);
     } else {
         // Initialize string with xml declaration
         $string = '';
         if ($this->options['addDecl']) {
             $string .= XML_Util::getXMLDeclaration($this->options['version'], $this->options['encoding']);
             $string .= $this->options['linebreak'];
         }
         if (!empty($this->options['name'])) {
             $string .= '<' . $this->options['name'] . '>' . $this->options['linebreak'];
             $this->_deep++;
             $indent = str_repeat($this->options['indent'], $this->_deep);
         }
     }
     if (!isset($string)) {
         $string = '';
     }
     if ($configuration_component instanceof __ConfigurationProperty) {
         $attributes = $this->options['useAttr'] ? $configuration_component->attributes : array();
         $string .= $indent . XML_Util::createTag($configuration_component->name, $attributes, $configuration_component->content, null, $this->options['useCData'] ? XML_UTIL_CDATA_SECTION : XML_UTIL_REPLACE_ENTITIES);
         $string .= $this->options['linebreak'];
     } else {
         if ($configuration_component instanceof __ConfigurationComment) {
             $string .= $indent . '<!-- ' . $configuration_component->content . ' -->';
             $string .= $this->options['linebreak'];
         } else {
             if ($configuration_component instanceof __ConfigurationSection) {
                 if (!$configuration_component->isRoot()) {
                     $string = $indent . '<' . $configuration_component->name;
                     $string .= $this->options['useAttr'] ? XML_Util::attributesToString($configuration_component->attributes) : '';
                 }
                 if ($children = count($configuration_component->children)) {
                     if (!$configuration_component->isRoot()) {
                         $string .= '>' . $this->options['linebreak'];
                     }
                     for ($i = 0; $i < $children; $i++) {
                         $string .= $this->toString($configuration_component->getChild($i));
                     }
                 }
                 if (!$configuration_component->isRoot()) {
                     if ($children) {
                         $string .= $indent . '</' . $configuration_component->name . '>' . $this->options['linebreak'];
                     } else {
                         $string .= '/>' . $this->options['linebreak'];
                     }
                 } else {
                     if (!empty($this->options['name'])) {
                         $string .= '</' . $this->options['name'] . '>' . $this->options['linebreak'];
                     }
                 }
             } else {
                 $string = '';
             }
         }
     }
     if (!$configuration_component->isRoot()) {
         $this->_deep--;
     }
     return $string;
 }
开发者ID:laiello,项目名称:lion-framework,代码行数:66,代码来源:XMLConfigurationStorage.class.php

示例8: htmlentities

print htmlentities(XML_Util::createCDataSection("I am content."));
print "\n<br><br>\n";
/**
 * creating a comment
 */
print "creating a comment:<br>";
print htmlentities(XML_Util::createComment("I am a comment."));
print "\n<br><br>\n";
/**
 * creating an XML tag with multiline mode
 */
$tag = array("qname" => "foo:bar", "namespaceUri" => "http://foo.com", "attributes" => array("key" => "value", "argh" => "fruit&vegetable"), "content" => "I'm inside the tag & contain dangerous chars");
print "creating a tag with qualified name and namespaceUri:<br>\n";
print "<pre>";
print htmlentities(XML_Util::createTagFromArray($tag, XML_UTIL_REPLACE_ENTITIES, true));
print "</pre>";
print "\n<br><br>\n";
/**
 * create an attribute string without replacing the entities
 */
$atts = array('series' => 'Starsky &amp; Hutch', 'channel' => 'ABC');
print "creating a attribute string, entities in values already had been replaced:<br>";
print htmlentities(XML_Util::attributesToString($atts, true, false, false, false, XML_UTIL_ENTITIES_NONE));
print "\n<br><br>\n";
/**
 * using the array-syntax for attributesToString()
 */
$atts = array('series' => 'Starsky &amp; Hutch', 'channel' => 'ABC');
print "using the array-syntax for attributesToString()<br>";
print htmlentities(XML_Util::attributesToString($atts, array('entities' => XML_UTIL_ENTITIES_NONE)));
print "\n<br><br>\n";
开发者ID:BackupTheBerlios,项目名称:dilps,代码行数:31,代码来源:example2.php

示例9: start_xref

 /**
  * @param  array
  * @return string
  * @access public
  */
 function start_xref($attributes)
 {
     if ($this->_secondPass) {
         return sprintf('<a href="#%s">%s</a>', isset($attributes['linkend']) ? $attributes['linkend'] : '', isset($this->_xref[$attributes['linkend']]) ? $this->_xref[$attributes['linkend']] : '');
     } else {
         return sprintf('<xref%s>', XML_Util::attributesToString($attributes));
     }
 }
开发者ID:Esleelkartea,项目名称:kz-adeada-talleres-electricos-,代码行数:13,代码来源:DocBook.php

示例10: createTagFromArray

 /**
  * create a tag from an array
  * this method awaits an array in the following format
  * <pre>
  * array(
  *  "qname"        => $qname         // qualified name of the tag
  *  "namespace"    => $namespace     // namespace prefix (optional, if qname is specified or no namespace)
  *  "localpart"    => $localpart,    // local part of the tagname (optional, if qname is specified)
  *  "attributes"   => array(),       // array containing all attributes (optional)
  *  "content"      => $content,      // tag content (optional)
  *  "namespaceUri" => $namespaceUri  // namespaceUri for the given namespace (optional)
  *   )
  * </pre>
  *
  * <code>
  * require_once 'XML/Util.php';
  *
  * $tag = array(
  *           "qname"        => "foo:bar",
  *           "namespaceUri" => "http://foo.com",
  *           "attributes"   => array( "key" => "value", "argh" => "fruit&vegetable" ),
  *           "content"      => "I'm inside the tag",
  *            );
  * // creating a tag with qualified name and namespaceUri
  * $string = PEAR_PackageFile_Generator_v2_XML_Util::createTagFromArray($tag);
  * </code>
  *
  * @access   public
  * @static
  * @param    array   $tag               tag definition
  * @param    integer $replaceEntities   whether to replace XML special chars in content, embedd it in a CData section or none of both
  * @param    boolean $multiline         whether to create a multiline tag where each attribute gets written to a single line
  * @param    string  $indent            string used to indent attributes (_auto indents attributes so they start at the same column)
  * @param    string  $linebreak         string used for linebreaks
  * @return   string  $string            XML tag
  * @see      PEAR_PackageFile_Generator_v2_XML_Util::createTag()
  * @uses     XML_Util::attributesToString() to serialize the attributes of the tag
  * @uses     XML_Util::splitQualifiedName() to get local part and namespace of a qualified name
  */
 function createTagFromArray($tag, $replaceEntities = PEAR_PackageFile_Generator_v2_XML_Util_REPLACE_ENTITIES, $multiline = false, $indent = "_auto", $linebreak = "\n", $encoding = PEAR_PackageFile_Generator_v2_XML_Util_ENTITIES_XML)
 {
     if (isset($tag["content"]) && !is_scalar($tag["content"])) {
         return XML_Util::raiseError("Supplied non-scalar value as tag content", PEAR_PackageFile_Generator_v2_XML_Util_ERROR_NON_SCALAR_CONTENT);
     }
     if (!isset($tag['qname']) && !isset($tag['localPart'])) {
         return XML_Util::raiseError('You must either supply a qualified name (qname) or local tag name (localPart).', PEAR_PackageFile_Generator_v2_XML_Util_ERROR_NO_TAG_NAME);
     }
     // if no attributes hav been set, use empty attributes
     if (!isset($tag["attributes"]) || !is_array($tag["attributes"])) {
         $tag["attributes"] = array();
     }
     // qualified name is not given
     if (!isset($tag["qname"])) {
         // check for namespace
         if (isset($tag["namespace"]) && !empty($tag["namespace"])) {
             $tag["qname"] = $tag["namespace"] . ":" . $tag["localPart"];
         } else {
             $tag["qname"] = $tag["localPart"];
         }
         // namespace URI is set, but no namespace
     } elseif (isset($tag["namespaceUri"]) && !isset($tag["namespace"])) {
         $parts = XML_Util::splitQualifiedName($tag["qname"]);
         $tag["localPart"] = $parts["localPart"];
         if (isset($parts["namespace"])) {
             $tag["namespace"] = $parts["namespace"];
         }
     }
     if (isset($tag["namespaceUri"]) && !empty($tag["namespaceUri"])) {
         // is a namespace given
         if (isset($tag["namespace"]) && !empty($tag["namespace"])) {
             $tag["attributes"]["xmlns:" . $tag["namespace"]] = $tag["namespaceUri"];
         } else {
             // define this Uri as the default namespace
             $tag["attributes"]["xmlns"] = $tag["namespaceUri"];
         }
     }
     // check for multiline attributes
     if ($multiline === true) {
         if ($indent === "_auto") {
             $indent = str_repeat(" ", strlen($tag["qname"]) + 2);
         }
     }
     // create attribute list
     $attList = XML_Util::attributesToString($tag["attributes"], true, $multiline, $indent, $linebreak);
     if (!isset($tag["content"]) || (string) $tag["content"] == '') {
         $tag = sprintf("<%s%s />", $tag["qname"], $attList);
     } else {
         if ($replaceEntities == PEAR_PackageFile_Generator_v2_XML_Util_REPLACE_ENTITIES) {
             $tag["content"] = PEAR_PackageFile_Generator_v2_XML_Util::replaceEntities($tag["content"], $encoding);
         } elseif ($replaceEntities == PEAR_PackageFile_Generator_v2_XML_Util_CDATA_SECTION) {
             $tag["content"] = XML_Util::createCDataSection($tag["content"]);
         }
         $tag = sprintf("<%s%s>%s</%s>", $tag["qname"], $attList, $tag["content"], $tag["qname"]);
     }
     return $tag;
 }
开发者ID:kaz6120,项目名称:Loggix,代码行数:96,代码来源:v2.php

示例11: serializeEl

 /**
  *  Serialize one metadata element
  *
  *  @param el object, element object
  *  @param lvl int, level for indentation
  *  @return string, serialized XML
  */
 function serializeEl($el, $lvl = 0)
 {
     $ind = str_repeat(" ", $lvl);
     $elNs = $el->ns;
     $elName = $el->name;
     $attrs = XML_Util::attributesToString($el->attrs);
     $fullName = ($elNs == '' ? '' : "{$elNs}:") . "{$elName}";
     $res = "\n{$ind}<{$fullName}{$attrs}>";
     $haveCh = count($el->children) > 0;
     foreach ($el->children as $ch) {
         $res .= $this->serializeEl($ch, $lvl + 1);
     }
     $res .= XML_Util::replaceEntities("{$el->content}");
     if ($haveCh) {
         $res .= "\n{$ind}";
     }
     $res .= "</{$fullName}>";
     return $res;
 }
开发者ID:romansavrulin,项目名称:Airtime,代码行数:26,代码来源:XmlParser.php

示例12: _startElement

 /**
  * SAX callback for 'startElement' event.
  *
  * @param  resource
  * @param  string
  * @param  array
  * @access private
  */
 function _startElement($parser, $element, $attributes)
 {
     $attributes = $this->canonicalize($attributes);
     $element = $this->canonicalize($element);
     $qElement = XML_Util::splitQualifiedName($element, '&MAIN');
     $process = $this->_lastProcessed != $element;
     // Push element's name and attributes onto the stack.
     $this->_level++;
     $this->_elementStack[$this->_level] = $element;
     $this->_attributesStack[$this->_level] = $attributes;
     if ($this->_checkDebug($element)) {
         $this->sendMessage(sprintf('startElement[%d]: %s %s', $this->_level, $element, XML_Util::attributesToString($attributes)));
     }
     if ($process && isset($this->_callbackRegistry->overloadedNamespaces[$qElement['namespace']]['active'])) {
         // The event is handled by a callback
         // that is registered for this namespace.
         $cdata = $this->_callbackRegistry->overloadedNamespaces[$qElement['namespace']]['object']->startElement($qElement['localPart'], $attributes);
     } else {
         // No callback was registered for this element's
         // opening tag, copy it.
         $cdata = sprintf('<%s%s>', $element, XML_Util::attributesToString($attributes));
     }
     $this->_cdataStack[$this->_level] = $cdata;
 }
开发者ID:Esleelkartea,项目名称:kz-adeada-talleres-electricos-,代码行数:32,代码来源:Transformer.php


注:本文中的XML_Util::attributesToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。