loadxml返回false:可能是什么原因?

时间:2015-10-13 11:47:03

标签: php xml domdocument

我需要解析XML字符串。当我在以下类中将字符串传递给pXML $this->loadXML($this->xmlString)时,它会返回false。这可能是什么原因?

class MXML extends DOMDocument {

        private $version,$encodingType,$rootNode,$videoParam,$encodingFormat,$audioParam,$xmlString;

        /**
         * Initilizes the DOM with version number and encoding
         * @param  $version
         * @param  $encoding
         */
        public function __construct($version,$encoding) {
            parent::__construct($version,$encoding);
            $this->formatOutput = true; // Nicely formats output with indentation and extra space.
        }

        public function pXML($xml) {
            $this->loadXML($this->xmlString); // returns FALSE
            $parameters = $this->getElementsByTagName("Parameter");
            $advanced = $this->getElementsByTagName("Advanced");
            $preprocessing = $this->getElementsByTagName("Preprocessing");
        }

        //..  write xml functions
};

以下是我致电pXML的方式:

$xml = new MXML();
$xml->pXML($result['XMLSettings']);

XML

<?xml version="1.0" encoding="iso-8859-1"?>
<Cutkompress-Parameters>
  <Video-Params>
    <EncodingFormat-MPEG-4Part2>
      <Parameter>
        <IQuant>7</IQuant>
        <PQuant>7</PQuant>
        <FramesToSkip>7</FramesToSkip>
        <PBetweenI>7</PBetweenI>
        <FrameRate>7</FrameRate>
        <SearchWindow>7</SearchWindow>
      </Parameter>
      <Advanced>
        <QuantType>7</QuantType>
        <QPel>ON</QPel>
        <MV>ON</MV>
        <SceneChange>Detect Medium Change</SceneChange>
        <VOL_Control_Parameters>ON</VOL_Control_Parameters>
      </Advanced>
      <Preprocessing>
        <NoiseReduction>Detect Medium Change</NoiseReduction>
        <SharpnessLevel>7</SharpnessLevel>
      </Preprocessing>
    </EncodingFormat-MPEG-4Part2>
  </Video-Params>
</Cutkompress-Parameters>

1 个答案:

答案 0 :(得分:3)

您没有解析传入pXML的字符串,而是尝试加载未在任何位置设置的$this->xmlString。您可能打算$this->loadXML($xml)

顺便说一句,你所得到的应该是给你一个警告。如果没有查看:How to get useful error messages in PHP?