本文整理汇总了PHP中XMLReader::moveToElement方法的典型用法代码示例。如果您正苦于以下问题:PHP XMLReader::moveToElement方法的具体用法?PHP XMLReader::moveToElement怎么用?PHP XMLReader::moveToElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XMLReader
的用法示例。
在下文中一共展示了XMLReader::moveToElement方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateVersionInfo
public static function generateVersionInfo($filename)
{
static $info;
if ($info) {
return $info;
}
if (!is_file($filename)) {
v("Can't find Version information file (%s), skipping!", $filename, E_USER_WARNING);
return array();
}
$r = new \XMLReader();
if (!$r->open($filename)) {
v("Can't open the version info file (%s)", $filename, E_USER_ERROR);
}
$versions = array();
while ($r->read()) {
if ($r->moveToAttribute("name") && ($funcname = str_replace(array("::", "->", "__", "_", '$'), array("-", "-", "-", "-", ""), $r->value)) && $r->moveToAttribute("from") && ($from = $r->value)) {
$versions[strtolower($funcname)] = $from;
$r->moveToElement();
}
}
$r->close();
$info = $versions;
return $versions;
}
示例2: 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);
}
}
示例3: 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));
}
}
示例4: generateVersionInfo
public static function generateVersionInfo($filename)
{
static $info;
if ($info) {
return $info;
}
$r = new \XMLReader();
if (!$r->open($filename)) {
throw new \Exception("Could not open file for accessing version information: {$filename}");
}
$versions = array();
while ($r->read()) {
if ($r->moveToAttribute("name") && ($funcname = str_replace(array("::", "->", "__", "_", '$'), array("-", "-", "-", "-", ""), $r->value)) && $r->moveToAttribute("from") && ($from = $r->value)) {
$versions[strtolower($funcname)] = $from;
$r->moveToElement();
}
}
$r->close();
$info = $versions;
return $versions;
}
示例5: getAttributes
/**
* Returns the given node's attributes as an associative array
*
* @param \XMLReader $reader
*
* @return array
*/
protected function getAttributes(\XMLReader $reader)
{
if (!$reader->hasAttributes) {
return array();
}
$attributes = array();
$reader->moveToFirstAttribute();
do {
$attributes[($reader->prefix ? $reader->prefix . ':' : '') . $reader->localName] = $reader->value;
} while ($reader->moveToNextAttribute());
$reader->moveToElement();
return $attributes;
}
示例6: traverse
/**
* Traverse XML tree
*
* Traverses the XML tree and calls the learnAutomaton() method for each
* element, with its child element nodes.
*
* @param DOMNode $root
* @return void
*/
protected function traverse(XMLReader $reader, $path = array())
{
$contents = array();
$whitespace = array();
$children = array();
$attributes = array();
// Learn attributes for this element
while ($reader->moveToNextAttribute()) {
$attributes[$reader->name] = $reader->value;
}
$reader->moveToElement();
// If this is an empty element, do not traverse, but return
// immediately.
if ($reader->nodeType === XMLReader::ELEMENT && $reader->isEmptyElement) {
$element = $this->getType($path);
$this->learnAutomaton($element, $children);
$this->learnSimpleType($element, $contents);
$this->learnAttributes($element, $attributes);
return;
}
// Traverse child elements.
while ($reader->read()) {
switch ($reader->nodeType) {
case XMLReader::ELEMENT:
// Opening tag
$child = array('namespace' => $reader->namespaceURI, 'name' => $reader->localName, 'parents' => $path);
$children[] = $child;
$childPath = array_merge($path, array($child));
// If we are in the document root, add the child as root
// element.
if (count($path) === 0) {
$this->rootElements[$child['name']] = $this->inferenceType($childPath);
}
$this->traverse($reader, $childPath);
break;
case XMLReader::END_ELEMENT:
// Closing tag
$element = $this->getType($path);
if (!count($children)) {
// Significant whitespace seems only significant if
// there are children, but there is still some
// whitespace.
$contents = array_merge($contents, $whitespace);
}
$this->learnAutomaton($element, $children);
$this->learnSimpleType($element, $contents);
$this->learnAttributes($element, $attributes);
return;
case XMLReader::TEXT:
case XMLReader::CDATA:
// Text content
$contents[] = $reader->value;
break;
case XMLReader::SIGNIFICANT_WHITESPACE:
$whitespace[] = $reader->value;
break;
}
}
}
示例7: getAttributes
private function getAttributes(XMLReader $xml, $attrsLists = 'all')
{
$attrs = array();
if (is_array($attrsLists)) {
foreach ($attrsLists as $attr) {
$attrs[$attr] = $xml->getAttribute($attr);
}
} else {
if ($attrsLists == 'all') {
while ($xml->moveToNextAttribute()) {
$attrs[$xml->name] = $xml->value;
}
}
}
// return the reader to the original Element
$xml->moveToElement();
return $attrs;
}
示例8: generateVersionInfo
public static function generateVersionInfo($filename)
{
static $info;
if ($info) {
return $info;
}
$r = new \XMLReader();
if (!$r->open($filename)) {
throw new \Exception();
}
$versions = array();
while ($r->read()) {
if ($r->moveToAttribute('name') && ($funcname = str_replace(array('::', '->', '__', '_', '$'), array('-', '-', '-', '-', ''), $r->value)) && $r->moveToAttribute('from') && ($from = $r->value)) {
$versions[strtolower($funcname)] = $from;
$r->moveToElement();
}
}
$r->close();
$info = $versions;
return $versions;
}
示例9: addslashes
$affectedProducts .= mysql_prep($reader->value);
$affectedProducts .= mysql_prep("<br>");
}
if ($reader->nodeType == XMLReader::END_ELEMENT && $reader->name == "affectedProducts" && $isAdvisory == "true") {
$isAffectedProducts = "false";
$affectedProducts = addslashes($affectedProducts);
}
/*REFERENCES - LINKS*/
if ($reader->nodeType == XMLReader::ELEMENT && $reader->name == "references" && $isAdvisory == "true") {
$isReferences = "true";
}
if ($reader->nodeType == XMLReader::ELEMENT && $reader->name == "link" && $isReferences == "true") {
$reader->moveToAttribute('target');
$linkTarget .= mysql_prep($reader->value);
$linkTarget .= ",";
$reader->moveToElement();
$reader->read();
$linkName .= mysql_prep($reader->value);
$linkName .= ",";
}
if ($reader->nodeType == XMLReader::END_ELEMENT && $reader->name == "references" && $isReferences == "true") {
$isReferences = "false";
$linkName = mysql_prep($linkName);
$linkTarget = mysql_prep($linkTarget);
}
/*FIX RECOMMENDATION*/
if ($reader->nodeType == XMLReader::ELEMENT && $reader->name == "fixRecommendation" && $isAdvisory == "true") {
$isFixRecommendation = "true";
$reader->moveToAttribute('type');
$fixRecommendation_type = mysql_prep($reader->value);
$fixRecommendation = mysql_prep("<p>");
示例10: parse
/**
* Parses the input code and returns the OPT XML tree.
*
* @param String $filename The file name (for debug purposes)
* @param String &$code The code to parse
* @return Opt_Xml_Root
*/
public function parse($filename, &$code)
{
$debug = array(XMLReader::NONE => 'NONE', XMLReader::ELEMENT => 'ELEMENT', XMLReader::ATTRIBUTE => 'ATTRIBUTE', XMLReader::TEXT => 'TEXT', XMLReader::CDATA => 'CDATA', XMLReader::ENTITY_REF => 'ENTITY_REF', XMLReader::ENTITY => 'ENTITY', XMLReader::PI => 'PI', XMLReader::COMMENT => 'COMMENT', XMLReader::DOC => 'DOC', XMLReader::DOC_TYPE => 'DOC_TYPE', XMLReader::DOC_FRAGMENT => 'DOC_FRAGMENT', XMLReader::NOTATION => 'NOTATION', XMLReader::WHITESPACE => 'WHITESPACE', XMLReader::SIGNIFICANT_WHITESPACE => 'SIGNIFICANT_WHITESPACE', XMLReader::END_ELEMENT => 'END_ELEMENT', XMLReader::END_ENTITY => 'END_ENTITY', XMLReader::XML_DECLARATION => 'XML_DECLARATION');
libxml_use_internal_errors(true);
$reader = new XMLReader();
$reader->xml($code);
// $reader->setParserProperty(XMLReader::LOADDTD, true);
// $reader->setParserProperty(XMLReader::VALIDATE, true);
$reader->setParserProperty(XMLReader::SUBST_ENTITIES, true);
$root = $current = new Opt_Xml_Root();
$firstElementMatched = false;
$depth = 0;
// Thanks, Oh Great PHP for your excellent WARNINGS!!! >:(
while (@$reader->read()) {
if ($reader->depth < $depth) {
$current = $current->getParent();
} elseif ($reader->depth > $depth) {
$current = $optNode;
}
// Opl_Debug::write($debug[$reader->nodeType].': '.$reader->name.', '.$reader->value);
switch ($reader->nodeType) {
// XML elements
case XMLReader::ELEMENT:
$optNode = new Opt_Xml_Element($reader->name);
// Parse element attributes, if you manage to get there
if ($reader->moveToFirstAttribute()) {
do {
// "xmlns" special namespace must be handler somehow differently.
if ($reader->prefix == 'xmlns') {
$ns = str_replace('xmlns:', '', $reader->name);
$root->addNamespace($ns, $reader->value);
// Let this attribute to appear, if it does not represent an OPT special
// namespace
if (!$this->_compiler->isNamespace($ns)) {
$optAttribute = new Opt_Xml_Attribute($reader->name, $reader->value);
$optNode->addAttribute($optAttribute);
}
} else {
$optAttribute = new Opt_Xml_Attribute($reader->name, $reader->value);
$optNode->addAttribute($optAttribute);
}
} while ($reader->moveToNextAttribute());
$reader->moveToElement();
}
// Set "rootNode" flag
if (!$firstElementMatched) {
$optNode->set('rootNode', true);
$firstElementMatched = true;
}
// Set "single" flag
if ($reader->isEmptyElement) {
$optNode->set('single', true);
}
$current->appendChild($optNode);
break;
case XMLReader::TEXT:
$this->_treeTextCompile($current, $reader->value);
break;
case XMLReader::COMMENT:
$optNode = new Opt_Xml_Comment($reader->value);
$current->appendChild($optNode);
break;
case XMLReader::CDATA:
$cdata = new Opt_Xml_Cdata($reader->value);
$cdata->set('cdata', true);
if ($current instanceof Opt_Xml_Text) {
$current->appendChild($cdata);
} else {
$text = new Opt_Xml_Text();
$text->appendChild($cdata);
$current->appendChild($text);
$current = $text;
}
break;
/* case XMLReader::SIGNIFICANT_WHITESPACE:
$cdata = new Opt_Xml_Cdata($reader->value);
$cdata->set('cdata', true);
if($current instanceof Opt_Xml_Text)
{
$current->appendChild($cdata);
}
else
{
$text = new Opt_Xml_Text();
$text->appendChild($cdata);
$current->appendChild($text);
$current = $text;
}
break;
*/
}
$depth = $reader->depth;
//.........这里部分代码省略.........
示例11: generateDeprecatedInfo
protected static function generateDeprecatedInfo($filename)
{
static $info;
if ($info) {
return $info;
}
if (!is_file($filename)) {
v("Can't find Version information file (%s), skipping!", $filename, E_USER_WARNING);
return array();
}
$r = new \XMLReader();
if (!$r->open($filename)) {
v("Can't open the version info file (%s)", $filename, E_USER_ERROR);
}
$deprecated = array();
while ($r->read()) {
if ($r->moveToAttribute("name") && ($funcname = str_replace(array("::", "->", "__", "_", '$'), array("_", "_", "_", "_", ""), $r->value)) && $r->moveToAttribute("deprecated") && ($value = $r->value)) {
$deprecated[strtolower($funcname)] = $value;
$r->moveToElement();
}
}
$r->close();
$info = $deprecated;
return $deprecated;
}
示例12: XMLReader
<?php
/* $Id$ */
$xmlstring = '<?xml version="1.0" encoding="UTF-8"?>
<books><book num="1"></book><test /></books>';
$reader = new XMLReader();
$reader->XML($xmlstring);
// 2 read to get on the 2nd node
$reader->read();
$reader->read();
if ($reader->nodeType != XMLREADER::END_ELEMENT) {
if ($reader->nodeType == XMLREADER::ELEMENT && $reader->hasAttributes) {
$attr = $reader->moveToFirstAttribute();
if ($reader->moveToElement()) {
if ($reader->name == 'book') {
echo "ok\n";
}
}
}
}
$reader->close();
?>
===DONE===
示例13: moveToElement
public function moveToElement()
{
return parent::moveToElement();
}