本文整理汇总了PHP中SimpleXMLIterator::attributes方法的典型用法代码示例。如果您正苦于以下问题:PHP SimpleXMLIterator::attributes方法的具体用法?PHP SimpleXMLIterator::attributes怎么用?PHP SimpleXMLIterator::attributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleXMLIterator
的用法示例。
在下文中一共展示了SimpleXMLIterator::attributes方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: attributes
/**
* Helper method to retrieve simplexml attributes
* @param string $ns
* @param boolean $is_prefix
* @return array
*/
function attributes($ns = null, $is_prefix = null)
{
$attr = (array) parent::attributes($ns, $is_prefix);
if (isset($attr['@attributes'])) {
return $attr['@attributes'];
}
return [];
}
示例2: _XMLNodeToArray
/**
* Recursively convert \SimpleXMLIterator to array
*
* @param \SimpleXMLIterator $XMLNode
*
* @return array
*/
private static function _XMLNodeToArray($XMLNode)
{
$result = array();
$attributes = $XMLNode->attributes();
foreach ($attributes as $k => $v) {
$val = (string) $v;
if ($val == "True" || $val == "False") {
$val = (bool) $val;
}
$result[$k] = $val;
}
$children = $XMLNode->children();
foreach ($children as $chK => $chNode) {
$result['Items'][] = self::_XMLNodeToArray($chNode);
}
return $result;
}
示例3: getChildrenValues
/**
* @param \SimpleXMLIterator $element
* @param \Twig_Template $template
*
* @param string $formId
* @param string $xPath
* @param string $requiredChildren
* @param array $identityRefs
*
* @return array|bool
*/
public function getChildrenValues($element, $template, $formId, $xPath = "", $requiredChildren = "", $identityRefs = array())
{
$retArr = array();
$targetAttributes = array('key', 'iskey', 'mandatory');
foreach ($element as $label => $el) {
$attributesArr = array_fill_keys($targetAttributes, false);
foreach ($element->attributes() as $name => $attr) {
if ($name == "key") {
$attributesArr[$name] = (string) $attr[0];
}
}
foreach ($el->attributes() as $name => $attr) {
if (in_array($name, array('iskey', 'mandatory'))) {
$attributesArr[$name] = (string) $attr[0];
}
}
if (($attributesArr['iskey'] !== "true" && $attributesArr['key'] == false || $requiredChildren !== "" && $label != $requiredChildren) && $attributesArr['mandatory'] == false) {
continue;
}
if ($attributesArr['key'] !== false) {
$requiredChildren = $attributesArr['key'];
} else {
$requiredChildren = "";
}
$twigArr = array();
$twigArr['key'] = "";
$twigArr['xpath'] = "";
$twigArr['element'] = $el;
$twigArr['useHiddenInput'] = true;
$twigArr['moduleIdentityRefs'] = $identityRefs;
$newXPath = $xPath . "/*";
$res = $this->getAvailableLabelValuesForXPath($formId, $newXPath);
$retArr[$label] = array();
if (isset($res['labelsAttributes'][$label])) {
$retArr[$label]['labelAttributes'] = $res['labelsAttributes'][$label];
}
$retArr[$label]['valueElem'] = $this->removeMultipleWhitespaces($template->renderBlock('configInputElem', $twigArr));
$retArr[$label]['children'] = $this->getChildrenValues($el, $template, $formId, $newXPath, $requiredChildren);
}
return sizeof($retArr) ? $retArr : false;
}
示例4: createFromXML
/**
* This class method is used to construct a ResourceDescriptor object by providing the XML for that object.
*
* @param string $xml - XML String defining ResourceDescriptor
* @return ResourceDescriptor
*/
public static function createFromXML($xml)
{
$sxi = new \SimpleXMLIterator($xml);
$temp = new self((string) $sxi->attributes()->name, (string) $sxi->attributes()->wsType, (string) $sxi->attributes()->uriString, (string) $sxi->attributes()->isNew);
$desc = !empty($sxi->description) ? (string) $sxi->description : null;
$label = !empty($sxi->label) ? (string) $sxi->label : null;
$date = !empty($sxi->creationDate) ? (string) $sxi->creationDate : null;
$temp->setLabel($label);
$temp->setDescription($desc);
$temp->setCreationDate($date);
foreach ($sxi->resourceDescriptor as $nestRd) {
$temp->children[] = ResourceDescriptor::createFromXML($nestRd->asXML());
}
foreach ($sxi->resourceProperty as $prop) {
$temp->properties[] = ResourceProperty::createFromXML($prop->asXML());
}
return $temp;
}
示例5: arrayFromXml
/**
* Create an Array from XML
*
* This method sets up the SimpleXMLIterator and starts the parsing
* of an xml body to iterate through it and transform it into
* an array that can be used by the developers.
*
* @param string $xml
* @return array An array mapped to the passed xml
*/
public static function arrayFromXml($xml)
{
// replace namespace defs
$xml = str_replace('xmlns=', 'ns=', $xml);
// catch libxml errors
libxml_use_internal_errors(true);
try {
$iterator = new SimpleXMLIterator($xml);
} catch(Exception $e) {
$xmlErrors = libxml_get_errors();
return new Frapi_Exception(
'Xml Parsing Failed',
'INVALID_XML',
400,
'xml_parsing'
);
libxml_clear_errors();
}
$xmlRoot = $iterator->getName();
$type = $iterator->attributes()->type;
// SimpleXML provides the root information on construct
self::$_xmlRoot = $iterator->getName();
self::$_responseType = $type;
// return the mapped array with the root element as the header
return array($xmlRoot => self::_iteratorToArray($iterator));
}
示例6: arrayFromXml
/**
* sets up the SimpleXMLIterator and starts the parsing
* @access public
* @param string $xml
* @return array array mapped to the passed xml
*/
public static function arrayFromXml($xml)
{
// SimpleXML provides the root information on construct
$iterator = new SimpleXMLIterator($xml);
$xmlRoot = Braintree_Util::delimiterToCamelCase($iterator->getName());
$type = $iterator->attributes()->type;
self::$_xmlRoot = $iterator->getName();
self::$_responseType = $type;
// return the mapped array with the root element as the header
return array($xmlRoot => self::_iteratorToArray($iterator));
}