本文整理汇总了PHP中SimpleXMLElement::attributes方法的典型用法代码示例。如果您正苦于以下问题:PHP SimpleXMLElement::attributes方法的具体用法?PHP SimpleXMLElement::attributes怎么用?PHP SimpleXMLElement::attributes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleXMLElement
的用法示例。
在下文中一共展示了SimpleXMLElement::attributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct($input)
{
$sxe = new \SimpleXMLElement($input);
$this->evec_method = (string) $sxe->attributes()->method;
$this->evec_version = (string) $sxe->attributes()->version;
foreach ($sxe->marketstat->type as $t) {
$id = (int) $t->attributes()->id;
$this->types[$id] = new \stdClass();
$this->types[$id]->buy = new \stdClass();
$this->types[$id]->buy->volume = (double) $t->buy->volume;
$this->types[$id]->buy->avg = (double) $t->buy->avg;
$this->types[$id]->buy->max = (double) $t->buy->max;
$this->types[$id]->buy->min = (double) $t->buy->min;
$this->types[$id]->buy->stddev = (double) $t->buy->stddev;
$this->types[$id]->buy->median = (double) $t->buy->median;
$this->types[$id]->buy->percentile = (double) $t->buy->percentile;
$this->types[$id]->sell = new \stdClass();
$this->types[$id]->sell->volume = (double) $t->sell->volume;
$this->types[$id]->sell->avg = (double) $t->sell->avg;
$this->types[$id]->sell->max = (double) $t->sell->max;
$this->types[$id]->sell->min = (double) $t->sell->min;
$this->types[$id]->sell->stddev = (double) $t->sell->stddev;
$this->types[$id]->sell->median = (double) $t->sell->median;
$this->types[$id]->sell->percentile = (double) $t->sell->percentile;
$this->types[$id]->all = new \stdClass();
$this->types[$id]->all->volume = (double) $t->all->volume;
$this->types[$id]->all->avg = (double) $t->all->avg;
$this->types[$id]->all->max = (double) $t->all->max;
$this->types[$id]->all->min = (double) $t->all->min;
$this->types[$id]->all->stddev = (double) $t->all->stddev;
$this->types[$id]->all->median = (double) $t->all->median;
$this->types[$id]->all->percentile = (double) $t->all->percentile;
}
}
示例2: unserializeXml
/**
* Unserialize SimpleXMLElement
*
* @param \SimpleXMLElement $element Element to unserialize
* @param string $classHint Hint to which class unserialize
*
* @return mixed unserialized object
*/
protected function unserializeXml(\SimpleXMLElement $element, $classHint = null)
{
if ($this->configValue("extractClassFrom", "tagName") == "tagName") {
$elementClassHint = $element->getName();
} else {
$xsiAttrs = $element->attributes("http://www.w3.org/2001/XMLSchema-instance");
if (!isset($xsiAttrs["type"])) {
throw new \Exception("Element {$element->getName()} has no {http://www.w3.org/2001/XMLSchema-instance}type attribute");
}
$elementClassHint = $xsiAttrs["type"];
}
$mapperClass = $this->configValue("mapperClasses", []);
if (isset($mapperClass[$elementClassHint])) {
$className = $mapperClass[$elementClassHint];
} else {
$className = $classHint ? $classHint : rtrim($this->configValue("classesNamespace", ""), '\\') . '\\' . $elementClassHint;
}
if (!class_exists($className, true)) {
throw new ClassNotFoundException("Class '{$className}' not found");
}
$classInstance = new $className();
$this->checkNodes($element->attributes(), $className, $classInstance);
$this->checkNodes($element->children(), $className, $classInstance);
return $classInstance;
}
示例3: createFromResponse
public static function createFromResponse(\SimpleXMLElement $response)
{
$chart = new Chart();
$chart->setFrom((int) $response->attributes()->from);
$chart->setTo((int) $response->attributes()->to);
return $chart;
}
示例4: parse
/**
* Parses a simple xml element and returns an executable string for a layout node
*
* @param SimpleXMLElement $element
* @param \EcomDev_LayoutCompiler_Contract_CompilerInterface $compiler
* @param null|string $blockIdentifier
* @param string[] $parentIdentifiers
* @return string|string[]
*/
public function parse(SimpleXMLElement $element, \EcomDev_LayoutCompiler_Contract_CompilerInterface $compiler, $blockIdentifier = null, $parentIdentifiers = array())
{
if (empty($element->attributes()->name)) {
return false;
}
return $this->getClassStatement(array((string) $element->attributes()->name));
}
示例5: xml2js
private function xml2js(SimpleXMLElement $xmlnode, $isRoot = true)
{
$jsnode = array();
if (!$isRoot) {
if (count($xmlnode->attributes()) > 0) {
$jsnode["@attribute"] = array();
foreach ($xmlnode->attributes() as $key => $value) {
$jsnode["@attribute"][$key] = (string) $value;
}
}
$textcontent = trim((string) $xmlnode);
if (count($textcontent) > 0) {
$jsnode['_'] = $textcontent;
}
foreach ($xmlnode->children() as $childxmlnode) {
$childname = $childxmlnode->getName();
if (!array_key_exists($childname, $jsnode)) {
$jsnode[$childname] = array();
}
array_push($jsnode[$childname], $this->xml2js($childxmlnode, false));
}
return $jsnode;
} else {
$nodename = $xmlnode->getName();
$jsnode[$nodename] = array();
array_push($jsnode[$nodename], $this->xml2js($xmlnode, false));
return json_encode($jsnode, JSON_PRETTY_PRINT);
}
}
示例6: recreate_img_tag
public function recreate_img_tag($tag)
{
// Supress SimpleXML errors
libxml_use_internal_errors(TRUE);
try {
$x = new SimpleXMLElement($tag);
// We only want to rebuild img tags
if ($x->getName() == 'img') {
// Get the attributes I'll use in the new tag
$alt = (string) $x->attributes()->alt;
$src = (string) $x->attributes()->src;
$classes = (string) $x->attributes()->class;
$class_segs = explode(' ', $classes);
// All images have a source
$img = '<img src="' . $src . '"';
// If alt not empty, add it
if (!empty($alt)) {
$img .= ' alt="' . $alt . '"';
}
// Only alignment classes are allowed
$allowed_classes = array('alignleft', 'alignright', 'alignnone', 'aligncenter');
if (in_array($class_segs[0], $allowed_classes)) {
$img .= ' class="' . $class_segs[0] . '"';
}
// Finish up the img tag
$img .= ' />';
return $img;
}
} catch (Exception $e) {
}
// Tag not an img, so just return it untouched
return $tag;
}
示例7: loadLanguage
/**
* Custom loadLanguage method
*
* @param string $path The path where to find language files.
*
* @return void
*
* @since 3.1
*/
public function loadLanguage($path = null)
{
$source = $this->parent->getPath('source');
if (!$source) {
$this->parent->setPath('source', JPATH_PLUGINS . '/' . $this->parent->extension->folder . '/' . $this->parent->extension->element);
}
$this->manifest = $this->parent->getManifest();
$element = $this->manifest->files;
if ($element) {
$group = strtolower((string) $this->manifest->attributes()->group);
$name = '';
if (count($element->children())) {
foreach ($element->children() as $file) {
if ((string) $file->attributes()->plugin) {
$name = strtolower((string) $file->attributes()->plugin);
break;
}
}
}
if ($name) {
$extension = "plg_{$group}_{$name}";
$lang = JFactory::getLanguage();
$source = $path ? $path : JPATH_PLUGINS . "/{$group}/{$name}";
$folder = (string) $element->attributes()->folder;
if ($folder && file_exists("{$path}/{$folder}")) {
$source = "{$path}/{$folder}";
}
$lang->load($extension . '.sys', $source, null, false, true) || $lang->load($extension . '.sys', JPATH_ADMINISTRATOR, null, false, true);
}
}
}
示例8: index
/**
* Add item index and level to class attribute
*
* @param SimpleXMLElement $node The node to add the index and level to
* @param array $args Callback arguments
*/
public static function index(SimpleXMLElement $node, $args)
{
if ($node->getName() == 'ul') {
// set up level
$level = $args['level'] / 2 + 1;
if ($level > 1) {
$node->addAttribute('class', 'uk-nav uk-nav-navbar');
} else {
$node->addAttribute('class', 'uk-navbar-nav');
}
}
if ($node->getName() == 'li') {
$css = '';
// parent
if (isset($node->div)) {
$css .= ' uk-parent';
$node->addAttribute('data-uk-dropdown', '');
}
// add li css classes
$node->attributes()->class = trim($node->attributes()->class . $css);
// add a/span css classes
$children = $node->children();
if ($firstChild = $children[0]) {
$firstChild->addAttribute('class', trim($firstChild->attributes()->class . $css));
}
}
unset($node->attributes()->icon);
}
示例9: getStatus
/**
* Returns the response status (OK = success, ERROR = error, null = invalid responses)
*
* @return string NULL
*/
public function getStatus()
{
if ($this->xml && $this->xml instanceof \SimpleXMLElement) {
return (string) $this->xml->attributes()->Status;
}
return null;
}
示例10: parse
/**
* Parses a simple xml element and returns an executable string for a layout node
*
* @param SimpleXMLElement $element
* @param \EcomDev_LayoutCompiler_Contract_CompilerInterface $compiler
* @param null|string $blockIdentifier
* @param string[] $parentIdentifiers
* @return string|string[]
*/
public function parse(SimpleXMLElement $element, CompilerInterface $compiler, $blockIdentifier = null, $parentIdentifiers = array())
{
if ($blockIdentifier !== null && !in_array($blockIdentifier, $parentIdentifiers, true)) {
$parentIdentifiers[] = $blockIdentifier;
}
$blockIdentifier = isset($element->attributes()->{$this->idAttribute}) ? (string) $element->attributes()->{$this->idAttribute} : null;
return $compiler->parseElements($element, $blockIdentifier, $parentIdentifiers);
}
示例11: getBootstrap
/**
* Get the bootstrap PHPUnit configuration attribute
*
* @return string The bootstrap attribute or empty string if not set
*/
public function getBootstrap()
{
if ($this->xml) {
return (string) $this->xml->attributes()->bootstrap;
} else {
return '';
}
}
示例12: getAttributes
protected function getAttributes(\SimpleXMLElement $node)
{
if (count($node->attributes()) > 0) {
$attr = (array) $node->attributes();
return $attr['@attributes'];
}
return array();
}
示例13: __construct
/**
* @param \SimpleXMLElement $node
*/
public function __construct(\SimpleXMLElement $node)
{
$this->node = $node;
$attrs = $this->node->attributes();
$this->name = (string) $attrs['name'];
$this->type = (string) $attrs['type'];
$this->relation = (string) $attrs['relation'];
}
示例14: __construct
public function __construct(\SimpleXMLElement $object)
{
$this->setURL((string) $object->attributes()->url);
$this->setData((string) $object);
$this->setFileName((string) $object->attributes()->file);
$this->setOrdering((string) $object->attributes()->id);
$this->setModified((string) $object->attributes()->modTime);
$this->setFiletype((string) $object->attributes()->format);
}
示例15: createFromXML
/**
* Convert the raw XML into an object
*
* @param \SimpleXMLElement $xml
* @return Mail
*/
public static function createFromXML(\SimpleXMLElement $xml)
{
$mail = new Mail();
if (isset($xml->attributes()['type'])) {
$mail->setType((string) $xml->attributes()['type']);
}
$mail->setValue((string) $xml);
return $mail;
}