本文整理汇总了PHP中XMLReader::close方法的典型用法代码示例。如果您正苦于以下问题:PHP XMLReader::close方法的具体用法?PHP XMLReader::close怎么用?PHP XMLReader::close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XMLReader
的用法示例。
在下文中一共展示了XMLReader::close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: scan
/**
* @throws RuntimeException
* @return array of arrays.
* array( 'dumpKey' => array( 'match1', 'match2' ) )
*/
public function scan()
{
$openSuccess = $this->reader->open($this->dumpLocation);
if (!$openSuccess) {
throw new RuntimeException('Failed to open XML: ' . $this->dumpLocation);
}
$result = array();
foreach ($this->query as $queryKey => $query) {
$result[$queryKey] = array();
// Make sure keys are returned even if empty
}
while ($this->reader->read() && $this->reader->name !== 'page') {
}
while ($this->reader->name === 'page') {
$element = new SimpleXMLElement($this->reader->readOuterXML());
$page = $this->getPageFromElement($element);
foreach ($this->query as $queryKey => $query) {
$match = $this->matchPage($page, $query);
if ($match) {
//TODO allow the user to choose what to return
$result[$queryKey][] = $page->getTitle()->getTitle();
}
}
$this->reader->next('page');
}
$this->reader->close();
return $result;
}
示例3: getClioNum
function getClioNum($appurl, $link)
{
$clio = $current = $currentA = "";
$reader = new XMLReader();
$clioQ = $appurl . '/getSingleStuff.xq?doc=' . $link . '_ead.xml§ion=summary';
$reader->open($clioQ);
while ($reader->read()) {
if ($reader->name == "unitid" && $reader->getAttribute("type") == "clio") {
if ($reader->nodeType == XMLReader::ELEMENT) {
$currentA = "clio";
} else {
if ($reader->nodeType == XMLReader::END_ELEMENT) {
$currentA = "";
}
}
}
//echo "{$reader->name} and $currentA<br />";
if ($reader->name == "#text" && $currentA == "clio") {
$clio = $reader->value;
// there can be only one
}
}
// end WHILE
$reader->close();
return $clio;
}
示例4: parseSparqlResults
/**
* Parse the passed in Sparql XML string into a more easily usable format.
*
* @param string $sparql
* A string containing Sparql result XML.
*
* @return array
* Indexed (numerical) array, containing a number of associative arrays,
* with keys being the same as the variable names in the query.
* URIs beginning with 'info:fedora/' will have this beginning stripped
* off, to facilitate their use as PIDs.
*/
public static function parseSparqlResults($sparql)
{
// Load the results into a XMLReader Object.
$xmlReader = new XMLReader();
$xmlReader->xml($sparql);
// Storage.
$results = array();
// Build the results.
while ($xmlReader->read()) {
if ($xmlReader->localName === 'result') {
if ($xmlReader->nodeType == XMLReader::ELEMENT) {
// Initialize a single result.
$r = array();
} elseif ($xmlReader->nodeType == XMLReader::END_ELEMENT) {
// Add result to results
$results[] = $r;
}
} elseif ($xmlReader->nodeType == XMLReader::ELEMENT && $xmlReader->depth == 3) {
$val = array();
$uri = $xmlReader->getAttribute('uri');
if ($uri !== NULL) {
$val['value'] = self::pidUriToBarePid($uri);
$val['uri'] = (string) $uri;
$val['type'] = 'pid';
} else {
//deal with any other types
$val['type'] = 'literal';
$val['value'] = (string) $xmlReader->readInnerXML();
}
$r[$xmlReader->localName] = $val;
}
}
$xmlReader->close();
return $results;
}
示例5: parseFile
/**
* @param \Closure $callback
*/
protected function parseFile(\Closure $callback)
{
while ($this->xmlr->localName == $this->node) {
try {
$sxe = new \SimpleXMLElement($this->xmlr->readOuterXml());
if (!$sxe instanceof \SimpleXMLElement) {
throw new \Exception("node is note SimpleXMLElement");
}
$callback($sxe);
} catch (\RuntimeException $e) {
throw new \RuntimeException($e->getMessage());
} catch (\Exception $e) {
if ($this->trace) {
echo sprintf("%s - %s - %s -%s\n", $e->getMessage(), $e->getFile(), $e->getLine(), $e->getTraceAsString());
}
if ($this->strict) {
throw new \RuntimeException($e->getMessage());
}
}
if ($this->debug) {
break;
}
$this->xmlr->next($this->node);
}
$this->xmlr->close();
}
示例6: doRewind
/**
* @inheritdoc
*/
protected function doRewind()
{
$this->reader->close();
$this->open($this->resource->getFile()->getPathname());
$this->key = -1;
$this->next();
}
示例7: initialize
/**
* Reads the configuration file and creates the class attributes
*
*/
protected function initialize()
{
$reader = new XMLReader();
$reader->open(parent::getConfigFilePath());
$reader->setRelaxNGSchemaSource(self::WURFL_CONF_SCHEMA);
libxml_use_internal_errors(TRUE);
while ($reader->read()) {
if (!$reader->isValid()) {
throw new Exception(libxml_get_last_error()->message);
}
$name = $reader->name;
switch ($reader->nodeType) {
case XMLReader::ELEMENT:
$this->_handleStartElement($name);
break;
case XMLReader::TEXT:
$this->_handleTextElement($reader->value);
break;
case XMLReader::END_ELEMENT:
$this->_handleEndElement($name);
break;
}
}
$reader->close();
if (isset($this->cache["dir"])) {
$this->logDir = $this->cache["dir"];
}
}
示例8: close
/**
* @inheritdoc
*/
public function close()
{
if (!isset($this->xmlReader)) {
throw new \RuntimeException('The resource needs to be open.');
}
$this->xmlReader->close();
unset($this->xmlReader);
}
示例9: parse
public function parse($file)
{
$this->currentFile = new \SplFileObject($file);
$this->path = [];
$this->xmlReader->open($file);
$this->read();
$this->xmlReader->close();
}
示例10: parse
/**
* Parse a beer XML, returning an array of the record objects found
*
* @param string $xml
* @return IRecipe[]|IEquipment[]|IFermentable[]|IHop[]|IMashProfile[]|IMisc[]|IStyle[]|IWater[]|IYeast[]
*/
public function parse($xml)
{
$this->xmlReader->XML($xml);
$records = array();
while ($this->xmlReader->read()) {
// Find records
if ($this->xmlReader->nodeType == \XMLReader::ELEMENT && isset($this->tagParsers[$this->xmlReader->name])) {
$recordParser = new $this->tagParsers[$this->xmlReader->name]();
/** @var $recordParser Record */
$recordParser->setXmlReader($this->xmlReader);
$recordParser->setRecordFactory($this->recordFactory);
$records[] = $recordParser->parse();
}
}
$this->xmlReader->close();
return $records;
}
示例11: assertDumpEnd
/**
* Asserts that the xml reader is at the final closing tag of an xml file and
* closes the reader.
*
* @param $tag string: (optional) the name of the final tag
* (e.g.: "mediawiki" for </mediawiki>)
*/
protected function assertDumpEnd($name = "mediawiki")
{
$this->assertNodeEnd($name, false);
if ($this->xml->read()) {
$this->skipWhitespace();
}
$this->assertEquals($this->xml->nodeType, XMLReader::NONE, "No proper entity left to parse");
$this->xml->close();
}
示例12: rewind
/**
* {@inheritdoc}
*/
public function rewind()
{
if ($this->xml) {
$this->xml->close();
}
$this->xml = new \XMLReader();
$this->xml->open($this->path);
$this->next();
}
示例13: importXML
function importXML($file)
{
global $opt;
$xr = new XMLReader();
if (!$xr->open($file)) {
$xr->close();
return;
}
$xr->read();
if ($xr->nodeType != XMLReader::ELEMENT) {
echo 'error: First element expected, aborted' . "\n";
return;
}
if ($xr->name != 'gkxml') {
echo 'error: First element not valid, aborted' . "\n";
return;
}
$startupdate = $xr->getAttribute('date');
if ($startupdate == '') {
echo 'error: Date attribute not valid, aborted' . "\n";
return;
}
while ($xr->read() && !($xr->name == 'geokret' || $xr->name == 'moves')) {
}
$nRecordsCount = 0;
do {
if ($xr->nodeType == XMLReader::ELEMENT) {
$element = $xr->expand();
switch ($xr->name) {
case 'geokret':
$this->importGeoKret($element);
break;
case 'moves':
$this->importMove($element);
break;
}
$nRecordsCount++;
}
} while ($xr->next());
$xr->close();
setSysConfig('geokrety_lastupdate', date($opt['db']['dateformat'], strtotime($startupdate)));
}
示例14: parse
/**
* Creates a Map of devices from the xml file
*
* @param string $fileName path to the xml file to parse
* @return Map of <deviceId ModelDevice>
*/
public static function parse($fileName, $validationSchema)
{
$devicesMap = array();
$deviceID = null;
$groupID = null;
$reader = new XMLReader();
$reader->open($fileName);
$fullFileName = dirname(__FILE__) . DIRECTORY_SEPARATOR . $validationSchema;
$reader->setRelaxNGSchema($fullFileName);
libxml_use_internal_errors(TRUE);
while ($reader->read()) {
if (!$reader->isValid()) {
throw new Exception(libxml_get_last_error()->message);
}
$nodeName = $reader->name;
switch ($reader->nodeType) {
case XMLReader::ELEMENT:
switch ($nodeName) {
case WURFL_Xml_Interface::DEVICE:
$groupIDCapabilitiesMap = array();
$deviceID = $reader->getAttribute(WURFL_Xml_Interface::ID);
$userAgent = $reader->getAttribute(WURFL_Xml_Interface::USER_AGENT);
$fallBack = $reader->getAttribute(WURFL_Xml_Interface::FALL_BACK);
$actualDeviceRoot = $reader->getAttribute(WURFL_Xml_Interface::ACTUAL_DEVICE_ROOT);
$currentCapabilityNameValue = array();
if ($reader->isEmptyElement) {
$device = new WURFL_Xml_ModelDevice($deviceID, $userAgent, $fallBack, $actualDeviceRoot);
$devicesMap[$deviceID] = $device;
}
break;
case WURFL_Xml_Interface::GROUP:
$groupID = $reader->getAttribute(WURFL_Xml_Interface::GROUP_ID);
$groupIDCapabilitiesMap[$groupID] = array();
break;
case WURFL_Xml_Interface::CAPABILITY:
$capabilityName = $reader->getAttribute(WURFL_Xml_Interface::CAPABILITY_NAME);
$capabilityValue = $reader->getAttribute(WURFL_Xml_Interface::CAPABILITY_VALUE);
$currentCapabilityNameValue[$capabilityName] = $capabilityValue;
$groupIDCapabilitiesMap[$groupID][$capabilityName] = $capabilityValue;
break;
}
break;
case XMLReader::END_ELEMENT:
if ($nodeName == WURFL_Xml_Interface::DEVICE) {
$device = new WURFL_Xml_ModelDevice($deviceID, $userAgent, $fallBack, $actualDeviceRoot, $groupIDCapabilitiesMap);
$devicesMap[$device->id] = $device;
}
break;
}
}
// end of while
$reader->close();
return $devicesMap;
}
示例15: Decode
public static function Decode($XMLResponse, &$isFault)
{
$responseXML = null;
try {
if (empty($XMLResponse)) {
throw new Exception("Given Response is not a valid SOAP response.");
}
$xmlDoc = new XMLReader();
$res = $xmlDoc->XML($XMLResponse);
if ($res) {
$xmlDoc->read();
$responseXML = $xmlDoc->readOuterXml();
$xmlDOM = new DOMDocument();
$xmlDOM->loadXML($responseXML);
$isFault = trim(strtoupper($xmlDoc->localName)) == self::$FaultMessage;
if ($isFault) {
$xmlDOM->loadXML($xmlDoc->readOuterXml());
}
switch ($xmlDoc->nodeType) {
case XMLReader::ELEMENT:
$nodeName = $xmlDoc->localName;
$prefix = $xmlDoc->prefix;
if (class_exists($nodeName)) {
$xmlNodes = $xmlDOM->getElementsByTagName($nodeName);
foreach ($xmlNodes as $xmlNode) {
//$xmlNode->prefix = "";
$xmlNode->setAttribute("_class", $nodeName);
$xmlNode->setAttribute("_type", "object");
}
}
break;
}
$responseXML = $xmlDOM->saveXML();
$unserializer = new XML_Unserializer();
$unserializer->setOption(XML_UNSERIALIZER_OPTION_COMPLEXTYPE, 'object');
$res = $unserializer->unserialize($responseXML, false);
if ($res) {
$responseXML = $unserializer->getUnserializedData();
}
$xmlDoc->close();
} else {
throw new Exception("Given Response is not a valid XML response.");
}
} catch (Exception $ex) {
throw new Exception("Error occurred while XML decoding");
}
return $responseXML;
}
开发者ID:christopherreay,项目名称:freeFreeCrowdfunding_ignitiondeck_crowdfunding,代码行数:48,代码来源:XMLEncoder.php