本文整理汇总了PHP中SimpleXmlElement::getName方法的典型用法代码示例。如果您正苦于以下问题:PHP SimpleXmlElement::getName方法的具体用法?PHP SimpleXmlElement::getName怎么用?PHP SimpleXmlElement::getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleXmlElement
的用法示例。
在下文中一共展示了SimpleXmlElement::getName方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addChild
/**
* Add the node to a position under the tree
*
* @param \SimpleXmlElement|Element $node
* @param Element $parent
*/
public function addChild($node, $parent = null)
{
if ($node instanceof \SimpleXmlElement) {
$name = $node->getName();
$attributes = (array) $node->attributes();
$content = trim((string) $node);
$element = new Element($name, $attributes, $content);
if (!$this->tree) {
$this->tree = $element;
} else {
if (!$parent) {
$parent = $this->tree;
}
$parent->addChild($element);
}
// Add child elements recursive
if ($node->count() > 0) {
foreach ($node as $childNode) {
$this->addChild($childNode, $element);
}
}
} else {
if ($node instanceof Element) {
if (!$this->tree) {
$this->tree = $node;
} else {
if (!$parent) {
$parent = $this->tree;
}
$parent->addChild($node);
}
}
}
}
示例2: getPath
/**
* Gets a path to a node via SPL Stack implementation
*
* Pass in the child node and will recurse up the XML tree to print out
* the path in the tree to that node
*
* <config>
* <path>
* <to>
* <node>
* Node Value
* </node>
* </to>
* </path>
* </config>
*
* If you pass in the "node" object, this will print out
* config/path/to/node/
*
* @param SimpleXmlElement $element Child element to find path to
*
* @return string
* @access public
*/
public function getPath(SimpleXmlElement $element)
{
$this->_iterator->push($element->getName() . '/');
if (!$element->getSafeParent()) {
return $this->_iterator->pop();
}
return $this->getPath($element->getParent()) . $this->_iterator->pop();
}
示例3: getPath
/**
* Gets a path to a node via array implementation
*
* Pass in the child node and will recurse up the XML tree to print out
* the path in the tree to that node
*
* <config>
* <path>
* <to>
* <node>
* Node Value
* </node>
* </to>
* </path>
* </config>
*
* If you pass in the "node" object, this will print out
* config/path/to/node/
*
* @param SimpleXmlElement $element Child element to find path to
*
* @return string
* @access public
*/
public function getPath(SimpleXmlElement $element)
{
$this->_iterator[] = $element->getName() . '/';
if (!$element->getSafeParent()) {
return array_pop($this->_iterator);
}
return $this->getPath($element->getParent()) . array_pop($this->_iterator);
}
示例4: arrayToXml
public static function arrayToXml(\SimpleXMLElement $object = null, $data = array())
{
foreach ($data as $key => $value) {
if (is_object($value)) {
$value = ArrayUtilsVTT::objectToArray($value);
}
if ($load = simplexml_load_string($value)) {
$keyXMl = null;
$doc = new \DOMDocument();
$doc->loadXML($object->asXML());
$appendXml = $doc->createDocumentFragment();
$keyXMl = is_numeric($key) ? StringUtilsVTT::ToPluralString($load->children()->getName()) : $key;
$stringXml = "<{$keyXMl}>";
foreach ($load as $item) {
$stringXml .= $item->asXML();
}
$stringXml .= "</{$keyXMl}>";
$appendXml->appendXML($stringXml);
$doc->documentElement->appendChild($appendXml);
$object = new \SimpleXmlElement($doc->saveXML());
continue;
}
if (is_array($value)) {
if (!is_numeric($key)) {
$new_object = $object->addChild($key);
} else {
$new_object = $object->addChild($object->getName());
}
self::arrayToXml($new_object, $value, false);
} else {
if (!is_numeric($key)) {
$object->addChild($key, $value);
} else {
$object->addChild($object->getName(), $value);
}
}
}
return $object;
}
示例5: singlePcmlToArray
/**
* given a single ->data or ->struct element, return an array containing its contents as old toolkit-style data description.
*
* @param \SimpleXmlElement $dataElement
* @return array
*/
public function singlePcmlToArray(\SimpleXmlElement $dataElement)
{
$tagName = $dataElement->getName();
// get attributes of this element.
$attrs = $dataElement->attributes();
// both struct and data have name, count (optional), usage
$name = isset($attrs['name']) ? (string) $attrs['name'] : '';
$count = isset($attrs['count']) ? (string) $attrs['count'] : '';
$usage = isset($attrs['usage']) ? (string) $attrs['usage'] : '';
$structName = isset($attrs['struct']) ? (string) $attrs['struct'] : '';
// fill this if we have a struct
$subElements = array();
// should all be data
if ($tagName == 'data') {
$type = isset($attrs['type']) ? (string) $attrs['type'] : '';
// if a struct then we need to recurse.
if ($type != 'struct') {
// regular type (char, int...), not a struct, so the data element's name is just 'name'.
$nameName = 'Name';
} else {
// it IS a struct.
// old toolkit uses DSName for a data structure's name.
$nameName = 'DSName';
$theStruct = null;
// init
// look for matching struct
if ($this->_pcmlStructs) {
// TODO verify type with is_array and count
foreach ($this->_pcmlStructs as $possibleStruct) {
$possStructAttrs = $possibleStruct->attributes();
if ($possStructAttrs['name'] == $structName) {
$theStruct = $possibleStruct;
$structAttrs = $possStructAttrs;
break;
}
}
}
// if struct was not found, generate error for log
if (!$theStruct) {
// $this->getConnection->logThis("PCML structure '$structName' not found.");
return null;
}
// if we got here, we found our struct.
// count can also be defined at the structure level. If so, it will override count from data level)
if (isset($structAttrs['count'])) {
$count = (string) $structAttrs['count'];
}
// "usage" (in/out/inherit) can be defined here, at the structure level.
$structUsage = isset($structAttrs['usage']) ? (string) $structAttrs['usage'] : '';
// if we're not inheriting from our parent data element, but there is a struct usage, use the struct's usage (input, output, or inputoutput).
if (!empty($structUsage) && $structUsage != 'inherit') {
$usage = $structUsage;
}
$structSubDataElementsXmlObj = $theStruct->xpath('data');
if ($structSubDataElementsXmlObj) {
foreach ($structSubDataElementsXmlObj as $subDataElementXmlObj) {
if ($subDataElementXmlObj->attributes()->usage == 'inherit') {
// subdata is inheriting type from us. Give it to them.
$subDataElementXmlObj->attributes()->usage = $usage;
}
// here's where the recursion comes in. Convert data and add to array for our struct.
$subElements[] = $this->singlePcmlToArray($subDataElementXmlObj);
}
}
}
$length = isset($attrs['length']) ? (string) $attrs['length'] : '';
$precision = isset($attrs['precision']) ? (string) $attrs['precision'] : '';
//$struct = (isset($attrs['struct'])) ? (string) $attrs['struct'] : ''; // if this is pointing to a struct name
// find CW data type equivalent of PCML data type
if (isset($this->_pcmlTypeMap[$type])) {
// a simple type mapping
$newType = (string) $this->_pcmlTypeMap[$type];
} elseif ($type == 'int') {
// one of the integer types. Need to use length to determine which one.
if ($length == '2') {
$newType = I5_TYPE_SHORT;
} elseif ($length == '4') {
$newType = I5_TYPE_INT;
} else {
$newType = '';
// no match
}
} else {
$newtype = '';
}
$newInout = isset($this->_pcmlInoutMap[$usage]) ? (string) $this->_pcmlInoutMap[$usage] : '';
// create new length using precision if necessary
if ($precision) {
$newLength = "{$length}.{$precision}";
} else {
$newLength = $length;
}
}
// count
//.........这里部分代码省略.........
示例6: getPathOfFileNodeToTarget
/**
* @param \SimpleXmlElement $node
* @param string $path
* @return string
*/
protected function getPathOfFileNodeToTarget($node, $path = '')
{
if ($node->getName() == 'target') {
return $this->_getBasePathFromTargetName((string) $node['name']) . $path;
}
$path = '/' . $node['name'] . $path;
$parent = $this->_getParentNode($node);
return $this->_getPathOfFileNodeToTarget($parent, $path);
}
示例7: parseResponse
protected function parseResponse($response)
{
$xml = new SimpleXmlElement($response);
$name = $xml->getName();
if (strpos($name, 'ErrorResponse') !== false) {
// ErrorResponse, ShipmentRatingErrorResponse, etc.
return (string) $xml->Response->Status->Condition->ConditionData;
}
if ((string) $xml->Rated != 'Y') {
return 'Shipment is not rated';
}
$services = $this->getServices();
return array($this->product_code => array('id' => $this->product_code, 'currency' => (string) $xml->CurrencyCode, 'est_delivery' => '', 'name' => $services[$this->product_code], 'rate' => (string) $xml->ShippingCharge));
}
示例8: singlePcmlToParam
/**
* given a single ->data or ->struct element, return a parameter object in the new toolkit style.
*
* @todo this needs more validation. It is possible that all parts are not set to create return
*
* @param \SimpleXmlElement $dataElement
* @return ProgramParameter
*/
public function singlePcmlToParam(\SimpleXmlElement $dataElement)
{
$tagName = $dataElement->getName();
// get attributes of this element.
$attrs = $dataElement->attributes();
// both struct and data have name, count (optional), usage
$name = isset($attrs['name']) ? (string) $attrs['name'] : '';
$count = isset($attrs['count']) ? (string) $attrs['count'] : '';
$usage = isset($attrs['usage']) ? (string) $attrs['usage'] : '';
$structName = isset($attrs['struct']) ? (string) $attrs['struct'] : '';
// fill this if we have a struct
$subElements = array();
// each item should have tag name <data>
if ($tagName != 'data') {
return false;
}
$type = isset($attrs['type']) ? (string) $attrs['type'] : '';
// Get initial value, if specified by PCML.
$dataValue = isset($attrs['init']) ? (string) $attrs['init'] : '';
// if a struct then we need to recurse.
if ($type == 'struct') {
$theStruct = null;
// init
// look for matching struct definition encountered earlier.
if ($this->_pcmlStructs) {
// @todo verify type with is_array and count
foreach ($this->_pcmlStructs as $possibleStruct) {
$possStructAttrs = $possibleStruct->attributes();
if ($possStructAttrs['name'] == $structName) {
$theStruct = $possibleStruct;
$structAttrs = $possStructAttrs;
break;
}
}
}
// if struct was not found, generate error for log
if (!$theStruct) {
// $this->getConnection->logThis("PCML structure '$structName' not found.");
return null;
}
// count can also be defined at the structure level. If so, it will override count from data level)
if (isset($structAttrs['count'])) {
$count = (string) $structAttrs['count'];
}
// "usage" (in/out/inherit) can be defined here, at the structure level.
$structUsage = isset($structAttrs['usage']) ? (string) $structAttrs['usage'] : '';
// if we're not inheriting from our parent data element, but there is a struct usage, use the struct's usage (input, output, or inputoutput).
if (!empty($structUsage) && $structUsage != 'inherit') {
$usage = $structUsage;
}
$structSubDataElementsXmlObj = $theStruct->xpath('data');
if ($structSubDataElementsXmlObj) {
foreach ($structSubDataElementsXmlObj as $subDataElementXmlObj) {
if ($subDataElementXmlObj->attributes()->usage == 'inherit') {
// subdata is inheriting type from us. Give it to them.
$subDataElementXmlObj->attributes()->usage = $usage;
}
// here's where the recursion comes in. Convert data and add to array for our struct.
$subElements[] = $this->singlePcmlToParam($subDataElementXmlObj);
}
}
}
/* explanation of the terms "length" and "precision" in PCML:
* http://publib.boulder.ibm.com/infocenter/iadthelp/v6r0/index.jsp?topic=/com.ibm.etools.iseries.webtools.doc/ref/rdtcattr.htm
*
* For "int" values, length is the number of bytes; precision represents the number of bits. (Can be ignored here)
* For zoned and packed values, length is the maximum number of digits; precision represents the maximum decimal places.
*
*/
$length = isset($attrs['length']) ? (string) $attrs['length'] : '';
$precision = isset($attrs['precision']) ? (string) $attrs['precision'] : '';
$passBy = '';
// default of blank will become 'ref'/Reference in XMLSERVICE. Blank is fine here.
if (isset($attrs['passby']) && $attrs['passby'] == 'value') {
$passBy = 'val';
// rare. PCML calls it 'value'. XMLSERVICE calls it 'val'.
}
// find new toolkit equivalent of PCML data type
if (isset($this->_pcmlTypeMap[$type])) {
// a simple type mapping
$newType = (string) $this->_pcmlTypeMap[$type];
} elseif ($type == 'int') {
// one of the integer types. Need to use length to determine which one.
if ($length == '2') {
$newType = '5i0';
// short ints have two bytes
} elseif ($length == '4') {
$newType = '10i0';
// normal ints have four bytes
} else {
$newType = '';
// no match
//.........这里部分代码省略.........