XML未在php中解析

时间:2017-08-25 04:22:02

标签: php laravel

在我的控制器中,我从DB读取数据。 (其中An error has occurred The application failed to start. Loading required package: cluster Loading required package: plyr Loading required package: dplyr Attaching package: ‘dplyr’ The following objects are masked from ‘package:plyr’: arrange, count, desc, failwith, id, mutate, rename, summarise, summarize The following objects are masked from ‘package:stats’: filter, lag The following objects are masked from ‘package:base’: intersect, setdiff, setequal, union Loading required package: DT Attaching package: ‘DT’ The following objects are masked from ‘package:shiny’: dataTableOutput, renderDataTable Loading required package: data.table Warning in library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called ‘data.table’ Loading required package: ggfortify Warning in library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called ‘ggfortify’ Loading required package: ggcorrplot Loading required package: ggplot2 Loading required package: ggraph Warning in library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called ‘ggraph’ Loading required package: ggthemes Warning in library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called ‘ggthemes’ Loading required package: imputeTS Loading required package: knitr Warning in library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called ‘knitr’ Loading required package: markdown Warning in library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called ‘markdown’ Loading required package: purrr Warning in library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called ‘purrr’ Loading required package: randomForest Warning in library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called ‘randomForest’ Loading required package: rCharts Warning in library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called ‘rCharts’ Loading required package: reshape2 Loading required package: rpivotTable Warning in library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called ‘rpivotTable’ Loading required package: rsconnect Warning in library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called ‘rsconnect’ Loading required package: shinythemes Loading required package: shinyapps Warning in library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called ‘shinyapps’ Loading required package: tibble Loading required package: tidyr Warning in library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called ‘tidyr’ Loading required package: tidyverse Warning in library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called ‘tidyverse’ Loading required package: vegan Warning in library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called ‘vegan’ Loading required package: VIM Warning in library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called ‘VIM’ Loading required package: visdat Warning in library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called ‘visdat’ Error in value[[3L]](cond) : could not find function "rpivotTableOutput" Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous> Execution halted.. 存储为XML内容。例如:AlarmDeatils 列包含

AlarmDeatils

我在控制器中读到那行;

<SiteAlarmDetails>
    <AlertId>89637</AlertId>
    <SiteCode>20157498</SiteCode>
    <SiteName>newport</SiteName>
    <TankNumber>4</TankNumber>
    <DispenserNumbedr>3</DispenserNumbedr>
    <HoseNumber>3</HoseNumber>
    <GradeId>11</GradeId>
    <GradeName>PULP98</GradeName>
    <AlarmUTCDateTime>2015-10-08T12:00:00</AlarmUTCDateTime>
    <AlarmClearedUTCDateTime>2015-10-08T22:00:00</AlarmClearedUTCDateTime>
    <UTCTimeZoneName>GMT Standard Time</UTCTimeZoneName>
    <AlarmVolume>0</AlarmVolume>
    <AlarmLevel>0</AlarmLevel>
    <TankCapacity>0</TankCapacity>
    <TankCapacityPercent>0</TankCapacityPercent>
    <TankOverfill>0</TankOverfill>
    <TankUllage>0</TankUllage>
    <ProductLoss>0</ProductLoss>
    <HoursElapsed>10</HoursElapsed>
    <WaterLevel>0</WaterLevel>
    <AvgSalesPerDay>0</AvgSalesPerDay>
    <DaysToStockOut>0</DaysToStockOut>
    <InvalidDataCount>0</InvalidDataCount>
    <ValidDataCount>0</ValidDataCount>
    <ZeroVolumeCount>0</ZeroVolumeCount>
    <ZeroProductLevelCount>0</ZeroProductLevelCount>
    <ZeroTotaliserAmountCount>0</ZeroTotaliserAmountCount>
</SiteAlarmDetails>

当我使用

  $tableAlarm = \DB::table('Alarm')
                ->where('Alarm.AlarmId', '=', $id)->first();

我得到了

 var_dump($tableAlarm);

我试图像<;>

一样解析 AlarmDeatils
object(stdClass)#241 (10) { ["AlarmId"]=> string(6) "245039" ["MessageNotificationId"]=> string(6) "219078" ["CompanyId"]=> string(2) "19" ["CompanyCode"]=> string(7) "MCCOLLS" ["AlertTypeId"]=> string(2) "23" ["AlarmDetails"]=> string(1408) "979381320106510Eyemouth Service Station2017-07-23T21:26:499999-12-31T23:59:59.9999999GMT Standard Time00000005000000000001-01-01T00:00:000001-01-01T00:00:000001-01-01T00:00:000000001-01-01T00:00:00" ["AlertProcessStateId"]=> string(1) "2" ["UTCDateTimeInserted"]=> string(27) "2017-07-24 02:15:36.9300000" ["UTCDateTimeUpdated"]=> string(27) "2017-07-24 02:15:36.9300000" ["RowDataVersion"]=> string(16) "00000000117D854B" }

但我没有得到任何东西:(我试图像处理xml一样;

$alertXml = simplexml_load_string( $tableAlarm->AlarmDetails);
 echo $alertXml;//Nothing printed

1 个答案:

答案 0 :(得分:1)

希望这会有所帮助。试试这个最简单的。

Try this code snippet here

<?php

$xmlString=<<<XML
<SiteAlarmDetails>
  <AlertId>89637</AlertId>
  <SiteCode>20157498</SiteCode>
  <SiteName>newport</SiteName>
  <TankNumber>4</TankNumber>
  <DispenserNumbedr>3</DispenserNumbedr>
  <HoseNumber>3</HoseNumber>
  <GradeId>11</GradeId>
  <GradeName>PULP98</GradeName>
  <AlarmUTCDateTime>2015-10-08T12:00:00</AlarmUTCDateTime>
  <AlarmClearedUTCDateTime>2015-10-08T22:00:00</AlarmClearedUTCDateTime>
  <UTCTimeZoneName>GMT Standard Time</UTCTimeZoneName>
  <AlarmVolume>0</AlarmVolume>
  <AlarmLevel>0</AlarmLevel>
  <TankCapacity>0</TankCapacity>
  <TankCapacityPercent>0</TankCapacityPercent>
  <TankOverfill>0</TankOverfill>
  <TankUllage>0</TankUllage>
  <ProductLoss>0</ProductLoss>
  <HoursElapsed>10</HoursElapsed>
  <WaterLevel>0</WaterLevel>
  <AvgSalesPerDay>0</AvgSalesPerDay>
  <DaysToStockOut>0</DaysToStockOut>
  <InvalidDataCount>0</InvalidDataCount>
  <ValidDataCount>0</ValidDataCount>
  <ZeroVolumeCount>0</ZeroVolumeCount>
  <ZeroProductLevelCount>0</ZeroProductLevelCount>
  <ZeroTotaliserAmountCount>0</ZeroTotaliserAmountCount>
</SiteAlarmDetails>
XML;

$xml=simplexml_load_string($xmlString);
echo (string)$xml->AlertId;//type-casted to string
echo PHP_EOL;
echo (string)$xml->SiteCode;
echo PHP_EOL;
echo (string)$xml->SiteName;