尝试从数据库中提取存储为blob的xml文件,并将提取的xml数据存储在php对象中

时间:2015-10-27 14:32:48

标签: php xml

我目前有一个包含存储为blob的xml文件的数据库。当我尝试使用sql提取这些数据时,我没有获得原始xml格式的数据,而只是xml文件中的一些文本。我已经尝试了很多方法,但到目前为止没有运气,任何人对如何做到这一点都有任何想法?

目的是确定需要哪个xml文件进行比较,从数据库中检索它并将其与另一个xml文件进行比较。

这是我一直在尝试的一件事:

                **//************THIS IS WHERE THE PROBLEM IS*************************
                if($databaseMatchedModelsObjects[$count] -> version == $maxVersion && $databaseMatchedModelsObjects[$count] -> release == $maxRelease){
                    $con2 = connect2();
                    $contentModel = $con2->prepare("SELECT fileName, type, size, content FROM model WHERE id=:id LIMIT 1");
                        //print_r($databaseMatchedModelsObjects[$count] -> mid);
                        $contentModel->bindParam('id',$databaseMatchedModelsObjects[$count] -> mid,PDO::PARAM_INT);
                        $contentModel->execute(array('id'=>$databaseMatchedModelsObjects[$count] -> mid));
                        $row = $contentModel->fetch();
                        //$sql_statement= "SELECT xmltype(content, nls_charset_id('CHAR_CS')).getclobval() rfile FROM model WHERE id =" . $databaseMatchedModelsObjects[$count] -> id;
                        //$sql_result = mysqli_query($con, $sql_prim);
                        //print_r($sql_result);
                        //if($row = @mysqli_fetch_array($result)) {
                        if($row) {
                        $finalModelToCompareTo = $row['content'];
                        //echo(simplexml_load_string());
                        //print_r(simplexml_load_string($finalModelToCompareTo));
                        //print_r($finalModelToCompareTo);
                        //$finalModelToCompareTo = $databaseMatchedModelsObjects[$count] -> content;
                        //print_r($databaseMatchedModelsObjects[$count] -> content);

                    }

               }

示例使用内容的var转储打印出来,只是一个完整打印的片段太长。这应该是xml格式。

string(15513) " G title sub title 0 English 0 date This is the top level of the Common Information Model.   This model contains the singleton, root Managed Object Class (MOC) ManagedElement under which the complete model is contained. Directly under ManagedElement are managed-function level classes SF, T, E and the root MOC of any managed functions. The Equipment Root MOC is in the Equipment Managed Object Model (MOM). The root MOC for a managed function is hosted in the managed function MOM. Deprecated, Contains product information for a Managed Element and ManagedFunction(s).  Replaced by ProductData The product number in ABC format.  For information, refer to Corporate Basic Standards. The product revision in the form R[1-9][A-Z].  For information, refer to Corporate Basic Standards. Common product name.

我将与示例代码进行比较的XML文件:

如何打印比较:

$uploaded_model = @simplexml_load_file($targetdir . "\\" . $fileinfo->getFilename()); print_r($uploaded_model);

SimpleXMLElement Object ( [dtdVersion] => G [momMetaData] => SimpleXMLElement Object ( [momTitle] => title [momSubTitle] => sub title [momIdentity] => SimpleXMLElement Object ( [docNum] => 0 [docLang] => English [docRev] => 0 [docDate] => date ) [createdBy] => SimpleXMLElement Object ( [signature] => xqichen ) ) [mim] => SimpleXMLElement Object ( [@attributes] => Array ( [author] => XQHE [contact] => ok@dektech.com.au [correction] => 0 [date] => 2014-11-22 [docNo] => [name] => CmwPm [namespace] => urn:com:CmwPm [namespacePrefix] => cmwpm [organization] => XDT/DEK [release] => 2 [revision] => A [version] => 2 ) [description] => Performance Management MOM. 3GPP defines Performance Management in 3GPP 32.401. [domainExtension] => SimpleXMLElement Object ( [@attributes] => Array ( [domain] => ECIM ) [extension] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [name] => MomName [value] => PM ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [name] => Version [value] => 2 ) ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [name] => ecimMomRelease [value] => 3 ) ) [3]
=> SimpleXMLElement Object ( [@attributes] => Array ( [name] => ecimMomCorrection [value] => 0 ) ) [4] => SimpleXMLElement Object ( [@attributes] => Array ( [name] => immNamespace [value] => MOM_NAME ) ) ) ) [implements] => SimpleXMLElement Object ( [@attributes] => Array ( [correction] => 0 [name] => ECIM_PM [release] => 3 [version] => 2 ) ) [struct] => Array ( [0] => SimpleXMLElement Object ( [@attributes]
=> Array ( [name] => MeasurementReaderNameValue ) [description] => This name value is used for real-time monitoring. The real-time monitoring is set up using a PM job of type REALTIMEJOB. [structMember] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [name] => currentValue ) [description] => Contains the real-time value of the measurement. This value can be read in conjunction with attribute lastUpdated to determine the value of counters in real time. [string] => SimpleXMLElement Object ( ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [name] => lastUpdated ) [description] => Contains the exact time the currentValue was last set. This attribute is used to determine how recent the value supplied in currentValue is. [derivedDataTypeRef] => SimpleXMLElement Object ( [@attributes] => Array ( [name] => DateTime ) [mimName] => CmwPm ) )

2 个答案:

答案 0 :(得分:1)

我设法解决了我的问题:

$xml = simplexml_load_string($finalModelToCompareTo);

XML似乎已在blob中转换为字符串,您需要使用此方法将其再次转换回SimpleXMLObject

答案 1 :(得分:0)

我认为它确实是一个XML文件。 string(15513) " G title sub title 0 En...表示与浏览器解析的XML文件相同,您只能看到明文值而不能看到XML标记。所以,不要担心你在打印输出中看到的损失。如果您使用 Ctrl + U 打开网页源,则可以看到完整的XML文件语法。

相关问题