本文整理汇总了PHP中XMLReader::moveToNextAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP XMLReader::moveToNextAttribute方法的具体用法?PHP XMLReader::moveToNextAttribute怎么用?PHP XMLReader::moveToNextAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XMLReader
的用法示例。
在下文中一共展示了XMLReader::moveToNextAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse
protected function parse()
{
$depth = 0;
$elements = array();
$elements_[$depth] =& $elements;
while ($this->xml->read()) {
switch ($this->xml->nodeType) {
case XMLReader::END_ELEMENT:
if ($this->xml->depth - 1 < $depth) {
$elements =& $elements_[$depth];
$element =& $elements[sizeof($elements) - 1];
$depth = $this->xml->depth - 1;
}
break;
case XMLReader::ATTRIBUTE:
# Read does not go through attributes :(
break;
case XMLReader::ELEMENT:
if (strlen($this->xml->name) == 0) {
continue;
}
if ($this->xml->depth > $depth) {
$depth = $this->xml->depth;
$elements_[$depth] =& $elements;
$elements =& $element['elements'];
}
$elements[] = array('tag' => $this->xml->name);
# Working Element
$element =& $elements[sizeof($elements) - 1];
# Attributes
if ($this->xml->hasAttributes) {
$this->xml->moveToFirstAttribute();
$element['attributes'] = array();
$element['attributes'][$this->xml->name] = $this->xml->value;
while ($this->xml->moveToNextAttribute()) {
$element['attributes'][$this->xml->name] = $this->xml->value;
}
}
if ($this->xml->isEmptyElement) {
if ($this->xml->depth - 1 < $depth) {
$elements =& $elements_[$depth];
$element =& $elements[sizeof($elements) - 1];
$depth = $this->xml->depth - 1;
}
}
break;
case XMLReader::TEXT:
case XMLReader::CDATA:
if (!isset($element['value'])) {
$element['value'] = $this->xml->value;
} else {
$element['value'] .= $this->xml->value;
}
break;
}
}
$this->elements = $elements;
}
示例2: parseInfo
protected function parseInfo(\XMLReader $xml, InfosAbstract $object)
{
// we don't read the name attribute for the module name as in previous jelix version, it has always to be the directory name
if ($object->type == 'application') {
$object->name = (string) $xml->getAttribute('name');
}
$object->createDate = (string) $xml->getAttribute('createdate');
$locale = array('label' => $this->locale, 'description' => $this->locale);
while ($xml->read()) {
if (\XMLReader::END_ELEMENT == $xml->nodeType && 'info' == $xml->name) {
break;
}
if ($xml->nodeType == \XMLReader::ELEMENT) {
$property = $xml->name;
if ('label' == $property || 'description' == $property) {
if ($xml->getAttribute('lang') == $locale[$property] || $locale[$property] == '') {
$xml->read();
$object->{$property} = $xml->value;
if ($locale[$property] == '') {
// let's mark we readed the element corresponding to the locale
$locale[$property] = '__readed__';
}
}
} elseif ('author' == $property || 'creator' == $property || 'contributor' == $property) {
$person = array();
while ($xml->moveToNextAttribute()) {
$attrName = $xml->name;
$person[$attrName] = $xml->value;
}
array_push($object->authors, $person);
} elseif ('licence' == $property) {
// we support licence and license, but store always as license
while ($xml->moveToNextAttribute()) {
$attrProperty = 'license' . ucfirst($xml->name);
$object->{$attrProperty} = $xml->value;
}
$xml->read();
$object->license = $xml->value;
} else {
// <version> <license> <copyright> <homepageURL> <updateURL>
// read attributes 'date', 'stability' etc ... and store them into versionDate, versionStability
while ($xml->moveToNextAttribute()) {
$attrProperty = $property . ucfirst($xml->name);
$object->{$attrProperty} = $xml->value;
}
$xml->read();
if ($property == 'version') {
$object->{$property} = $this->fixVersion($xml->value);
} else {
$object->{$property} = $xml->value;
}
}
}
}
return $object;
}
示例3: writeReaderImpl
private function writeReaderImpl(XMLWriter $writer, XMLReader $reader)
{
switch ($reader->nodeType) {
case XMLReader::ELEMENT:
$writer->startElement($reader->name);
if ($reader->moveToFirstAttribute()) {
do {
$writer->writeAttribute($reader->name, $reader->value);
} while ($reader->moveToNextAttribute());
$reader->moveToElement();
}
if ($reader->isEmptyElement) {
$writer->endElement();
}
break;
case XMLReader::END_ELEMENT:
$writer->endElement();
break;
case XMLReader::COMMENT:
$writer->writeComment($reader->value);
break;
case XMLReader::SIGNIFICANT_WHITESPACE:
case XMLReader::TEXT:
$writer->text($reader->value);
break;
case XMLReader::PI:
$writer->writePi($reader->name, $reader->value);
break;
default:
XMLReaderNode::dump($reader);
}
}
示例4: parseEntrypoints
protected function parseEntrypoints(\XMLReader $xml, InfosAbstract $object)
{
$property = $xml->name;
while ($xml->read()) {
if ($xml->nodeType == \XMLReader::END_ELEMENT && 'entrypoints' == $xml->name) {
break;
}
if ($xml->nodeType == \XMLReader::ELEMENT) {
$id = $config = '';
$type = 'classic';
while ($xml->moveToNextAttribute()) {
if ($xml->name == 'file') {
$id = $xml->value;
} else {
if ($xml->name == 'config') {
$config = $xml->value;
} else {
if ($xml->name == 'type') {
$type = $xml->value;
}
}
}
}
if ($id) {
if (strpos($id, '.php') === false) {
$id .= '.php';
}
$object->entrypoints[$id] = array('config' => $config, 'file' => $id, 'type' => $type);
}
}
}
}
示例5: readAttributes
/**
* Read the attributes of the current element, and restructure them into a GpxLatLong object
*
* @param \XMLReader $xmlReader The XMLReader object pointing to the current element whose attributes we want to reformat as an object
* @return \GpxReader\GpxLatLong
**/
protected function readAttributes(\XMLReader $xmlReader)
{
$attributes = new GpxLatLong();
if ($xmlReader->hasAttributes) {
while ($xmlReader->moveToNextAttribute()) {
$this->mapAttributes($xmlReader->name, $xmlReader->value, $attributes);
}
}
return $attributes;
}
示例6: getAttributesFromNode
private function getAttributesFromNode(BasicXmlReader $xml)
{
if (!$xml->hasAttributes) {
return null;
}
$attributes = [];
while ($xml->moveToNextAttribute()) {
$attributes[$xml->name] = $xml->value;
}
return $attributes;
}
示例7: parse
public function parse(\XMLReader $xmlReader, $startingDepth = 0, $parseOne = false)
{
if ($this->callback !== null) {
$node = new Node();
$node->name = $xmlReader->name;
$node->depth = $xmlReader->depth;
$node->text = $xmlReader->readString();
if ($xmlReader->hasAttributes && $xmlReader->moveToFirstAttribute()) {
do {
$node->attributes[$xmlReader->name] = $xmlReader->value;
} while ($xmlReader->moveToNextAttribute());
$xmlReader->moveToElement();
}
$callback = $this->callback;
$callback($this->processNode($node, $xmlReader));
}
}
示例8: parseEntrypoints
protected function parseEntrypoints(XMLReader $xml, $object)
{
if (XMLReader::ELEMENT == $xml->nodeType && 'entrypoints' == $xml->name) {
$property = $xml->name;
while ($xml->read()) {
if ($xml->nodeType == XMLReader::END_ELEMENT && 'entrypoints' == $xml->name) {
break;
}
if ($xml->nodeType == XMLReader::ELEMENT) {
$entrypoint = array();
while ($xml->moveToNextAttribute()) {
$attrName = $xml->name;
$entrypoint[$attrName] = $xml->value;
}
array_push($object->{$property}, $entrypoint);
}
}
}
return $object;
}
示例9: initCountries
private function initCountries()
{
$reader = new XMLReader();
$reader->open(self::XMLPATH);
$countries = array();
while ($reader->read()) {
if ($reader->name != "iso_3166_entry") {
continue;
}
$country = array();
while ($reader->moveToNextAttribute()) {
$country[$reader->name] = $reader->value;
}
if (array_key_exists('alpha_2_code', $country)) {
$countries[$country['alpha_2_code']] = $country;
}
}
$reader->close();
self::$countries = $countries;
}
示例10: parseDependencies
protected function parseDependencies(XMLReader $xml, $object)
{
if (XMLReader::ELEMENT == $xml->nodeType && 'dependencies' == $xml->name) {
$property = $xml->name;
while ($xml->read()) {
if ($xml->nodeType == XMLReader::END_ELEMENT && 'dependencies' == $xml->name) {
break;
}
if ($xml->nodeType == XMLReader::ELEMENT) {
$dependency = array();
$dependency['type'] = $xml->name;
while ($xml->moveToNextAttribute()) {
$attrName = $xml->name;
$dependency[$attrName] = $xml->value;
}
array_push($object->{$property}, $dependency);
}
}
}
return $object;
}
示例11: _readObject
protected function _readObject(\XMLReader $xml, $class, $root = false)
{
$deConfig = $this->configProvider->getConfig($class)->deserialization;
if (!isset($deConfig)) {
throw new \Exception("No config count for {$class}");
}
// TODO handle simple value objecty things (XmlValue)
$ignorableAttributes = array();
if (!empty($deConfig->subClasses)) {
if (!empty($deConfig->discriminator)) {
if (substr($deConfig->discriminator, 0, 1) !== '@') {
throw new \Exception("Unsupported discriminator, currently only attributes (denoted with @) are supported. Found: " . $deConfig->discriminator);
}
$discrimName = substr($deConfig->discriminator, 1);
$attrNS = $xml->namespaceURI ? $xml->namespaceURI . ':' : '';
$ignorableAttributes[$attrNS . $discrimName] = true;
$discrimValue = $xml->getAttribute($discrimName);
foreach ($deConfig->subClasses as $subClass) {
$subConfig = $this->configProvider->getConfig($subClass)->deserialization;
if ($subConfig->discriminatorValue == $discrimValue) {
$class = $subClass;
$deConfig = $subConfig;
break;
}
}
} elseif ($root && ($xml->name != $deConfig->name || $xml->namespaceURI != $deConfig->namespace)) {
$matchName = $xml->name;
$matchNS = $xml->namespaceURI;
foreach ($deConfig->subClasses as $subClass) {
$subConfig = $this->configProvider->getConfig($subClass)->deserialization;
if ($subConfig->name == $matchName && $subConfig->namespace == $matchNS) {
$class = $subClass;
$deConfig = $subConfig;
break;
}
}
}
}
$fullName = $xml->namespaceURI . ':' . $xml->name;
if ($root && ($xml->name != $deConfig->name || $xml->namespaceURI != $deConfig->namespace)) {
throw new \Exception("Unable to resolve root node for {$fullName}");
}
$creatorClass = $class;
if (!empty($deConfig->factoryClass)) {
$creatorClass = $deConfig->factoryClass;
}
if (!empty($deConfig->factoryMethod)) {
$creatorMethod = $deConfig->factoryMethod;
$object = $creatorClass::$creatorMethod();
} else {
$object = new $class();
}
$seenAttributes = array();
$seenElements = array();
$namespace = $xml->namespaceURI;
if ($xml->hasAttributes) {
while ($xml->moveToNextAttribute()) {
$attrNS = $xml->namespaceURI ? $xml->namespaceURI . ':' : (isset($namespace) ? $namespace . ':' : '');
$fullName = $attrNS . $xml->name;
if ($xml->name === 'xmlns') {
continue;
}
if (isset($ignorableAttributes[$fullName])) {
continue;
}
if (!isset($deConfig->attributes[$fullName])) {
throw new \Exception("Unknown attribute found in {$class}: {$fullName}");
}
$val = $this->_readAttribute($xml, $deConfig->attributes[$fullName]);
$this->_setProperty($object, $deConfig->attributes[$fullName]->property, $val);
$seenAttributes[] = $deConfig->attributes[$fullName]->property->id;
}
$xml->moveToElement();
}
$knownValues = array();
if (!$xml->isEmptyElement) {
while (true) {
if (!$xml->read()) {
throw new \Exception("XML read error");
}
switch ($xml->nodeType) {
case \XMLReader::ELEMENT:
list($propType, $val) = $this->_readElement($xml, $deConfig);
$seenElements[] = $propType->id;
if (is_array($val)) {
if (!isset($knownValues[$propType->id])) {
$knownValues[$propType->id] = array($propType, array());
}
$knownValues[$propType->id][1] = array_merge($knownValues[$propType->id][1], $val);
} else {
$this->_setProperty($object, $propType, $val);
}
break;
case \XMLReader::END_ELEMENT:
break 2;
case \XMLReader::WHITESPACE:
case \XMLReader::COMMENT:
case \XMLReader::SIGNIFICANT_WHITESPACE:
break;
default:
//.........这里部分代码省略.........
示例12: parseRootAttributes
protected function parseRootAttributes(\XMLReader $reader)
{
while ($reader->moveToNextAttribute()) {
$name = $reader->name;
$value = $reader->value;
$this->document->setMetadataValue($name, $value);
}
}
示例13: processAttributes
/**
* Process element attributes
*
* @param \XMLReader $reader
* @param \stdClass $tree
*/
public function processAttributes(&$reader, &$tree)
{
$name = $reader->name;
$node = new \stdClass();
$node->attr = new \stdClass();
while ($reader->moveToNextAttribute()) {
$node->attr->{$name} = $reader->value;
}
if (isset($tree->{$name}) && is_a($tree->{$name}, 'ArrayObject')) {
$lastKey = $tree->{$name}->count() - 1;
$node->value = $tree->{$name}->offsetGet($lastKey);
$tree->{$name}->offsetSet($lastKey, $node);
} else {
$node->value = isset($tree->{$name}) ? $tree->{$name} : '';
$tree->{$name} = $node;
}
}
示例14: ParseXmlFileData
public function ParseXmlFileData($xml)
{
$obReader = new XMLReader();
$obReader->open($xml, "utf-8");
if (!$obReader) {
$this->LAST_ERROR = "Ошибка чтения xml файла";
return false;
}
$arDatum = array();
$arCatStructs = array();
$arCatalogs = array();
$arOrders = array();
$arSchedules = array();
$arMasterstats = array();
while ($obReader->read()) {
switch ($obReader->nodeType) {
case XMLReader::ELEMENT:
// если users
if ($obReader->localName == 'Users') {
$obReader->getAttribute("Full");
$arParams = array("full" => 1);
if ($obReader->getAttribute("Full") == "FALSE") {
$arParams = array("full" => 0);
}
self::ArrayToFile($arParams, 'arParams', $this->sDir . 'params.php');
$arUser = array();
$iCount = 0;
while ($obReader->read()) {
if ($obReader->nodeType == XMLReader::ELEMENT) {
if ($obReader->localName == 'User') {
$arUser = array();
//приходим в user
$obReader->moveToNextAttribute();
//берем атрибут id
$arUser[$obReader->localName] = $obReader->value;
while ($obReader->read()) {
if ($obReader->nodeType == XMLReader::END_ELEMENT && $obReader->localName == 'User') {
break;
}
if ($obReader->nodeType == XMLReader::ELEMENT) {
//сохраняем значения
$sName = $obReader->localName;
$obReader->read();
if ($obReader->nodeType !== XMLReader::END_ELEMENT) {
$arUser[$sName] = $obReader->value;
}
}
}
}
//заносим user в массив $arUsers
$arDatum[$iCount] = $arUser;
$iCount++;
}
}
self::ArrayToFile($arDatum, 'arUsers', $this->sDir . 'users.php');
$this->step = $_SESSION['sStep'] = 'addUsers';
}
/*** Catalog Structure ***/
if ($obReader->localName == 'CatalogStructures') {
$obReader->getAttribute("Full");
$arParams = array("full" => 1);
if ($obReader->getAttribute("Full") == "FALSE") {
$arParams = array("full" => 0);
}
self::ArrayToFile($arParams, 'arParams', $this->sDir . 'params.php');
$arUser = array();
$iCount = 0;
while ($obReader->read()) {
if ($obReader->nodeType == XMLReader::ELEMENT) {
if ($obReader->localName == 'CatalogStructure') {
$arCatStruct = array();
//приходим в user
$obReader->moveToNextAttribute();
//берем атрибут id
$arCatStruct[$obReader->localName] = $obReader->value;
while ($obReader->read()) {
if ($obReader->nodeType == XMLReader::END_ELEMENT && $obReader->localName == 'CatalogStructure') {
break;
}
if ($obReader->nodeType == XMLReader::ELEMENT) {
//сохраняем значения
$sName = $obReader->localName;
$obReader->read();
if ($obReader->nodeType !== XMLReader::END_ELEMENT) {
$arCatStruct[$sName] = $obReader->value;
}
}
}
}
//заносим user в массив $arCatStructs
$arCatStructs[$iCount] = $arCatStruct;
$iCount++;
}
}
self::ArrayToFile($arCatStructs, 'arCatStructs', $this->sDir . 'catstruct.php');
$this->step = $_SESSION['sStep'] = 'addCatStructs';
}
/*** Catalog ***/
if ($obReader->localName == 'Catalogs') {
$obReader->getAttribute("Full");
//.........这里部分代码省略.........
示例15: _getXmlNode
/**
* Process a node from the XML Map
* It is permitted for the XML to just define one or more tables without fields (when the 'use headers' option is used)
*
* Note: Calls itself recursively to process a tree
*
* @return bool returns true if all fine else false
*/
private function _getXmlNode($node_content, $current_record, $xml_path)
{
$jinput = JFactory::getApplication()->input;
$csvilog = $jinput->get('csvilog', null, null);
$current_node = '';
$xml_schema = new XMLReader();
/**
* Add a wrapper to make the XML viable and ensure that self closing tags contain a space before the '/>'
* The XML may still be invalid but that's down to what the user entered
*/
$node_content = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<da_root>" . $node_content . '</da_root>';
$xml_schema->XML($node_content);
// XML file to table map is valid XML - construct the arrays used in file extraction
$use_read = true;
// The XML could only be validated against a DTD if the syntax of the XML used for the map is made more complex
$validate_xml = false;
if ($validate_xml == true) {
// Note: When the DTD is external, the property value must be set before the first read()
$xml_schema->setParserProperty(XMLReader::VALIDATE, true);
}
while ($use_read ? $xml_schema->read() : $xml_schema->next()) {
// Validation checking disabled because a DTD (or RELAX NG) schema is required.
if ($validate_xml == true) {
if ($xml_schema->isValid() == false) {
$xml_schema->close();
return false;
}
}
// Default to a reading a single node in the next loop
$use_read = true;
// Ignore any node associated with the root
if ($xml_schema->name == 'da_root') {
continue;
}
// Process start elements
if ($xml_schema->nodeType == XMLReader::ELEMENT) {
$self_closing = $xml_schema->isEmptyElement;
// Ready to add a new node - but only if the last node was closed
if (!empty($current_node)) {
$csvilog->AddStats('incorrect', JText::sprintf('COM_CSVI_XML_NODE_UNCLOSED', $current_node));
return false;
}
// A new node was found - Check whether this is a new record type
if (empty($current_record)) {
// New record type
// Check for a self-closing node
$self_closing = $xml_schema->isEmptyElement;
$current_record = strtolower($xml_schema->name);
$this->_xml_records[] = strtolower($current_record);
// Store any attributes
while ($xml_schema->moveToNextAttribute()) {
// Note1: $xml_schema->hasValue only indicates whether the element can have a value, not whether it does
// Note2: empty($xml_schema->value) always return true, regardless of the actual value
$value = $xml_schema->value;
if (!empty($value)) {
if ($this->_isXmlFieldNameValid($xml_schema->value)) {
$this->_xml_schema[$current_record]['attrs'][strtolower($xml_schema->name)] = trim($xml_schema->value);
} else {
$csvilog->AddStats('incorrect', JText::sprintf('COM_CSVI_XML_FILE_MAP_NO_REFERENCE', $xml_schema->value));
$xml_schema->close();
return false;
}
}
}
// Check for a self-closing node
if ($self_closing == true) {
$current_record = '';
}
} else {
// New field type
$current_node = strtolower($xml_schema->name);
$current_path = $this->_getXmlNodePath($xml_path, $current_node);
// Store any attributes
while ($xml_schema->moveToNextAttribute()) {
// Note1: $xml_schema->hasValue only indicates whether the element can have a value, not whether it does
// Note2: empty($xml_schema->value) always return true, regardless of the actual value
$value = $xml_schema->value;
if (!empty($value)) {
if ($this->_isXmlFieldNameValid($xml_schema->value)) {
$this->_xml_schema[$current_record]['nodes'][$current_path]['attrs'][strtolower($xml_schema->name)] = trim($xml_schema->value);
} else {
$csvilog->AddStats('incorrect', JText::_('COM_CSVI_XML_FILE_MAP_NO_REFERENCE', $xml_schema->value));
$xml_schema->close();
return false;
}
}
}
$sub_node_content = $xml_schema->readInnerXML();
// Check whether there are any lower level nodes
if (strstr($sub_node_content, '<') === false) {
/**
* Content has no embedded nodes - Assume a field name
//.........这里部分代码省略.........