简体   繁体   English

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

[英]Trying to extract an xml file stored as a blob from a database and storing the extracted xml data in a php object

I currently have a database which contains xml files stored as blobs. 我目前有一个数据库,其中包含以blob存储的xml文件。 When I attempt to extract this data using sql I am not getting the data in the original xml format rather just bits of text from the xml file. 当我尝试使用sql提取此数据时,我没有以原始xml格式获取数据,而只是从xml文件中获取了一些文本。 I have tried a number of ways but no luck so far anyone have any ideas on how to do this? 我已经尝试了多种方法,但到目前为止,还没有运气的人对如何执行此操作有任何想法?

The aim is to determine which xml file is needed for comparison, to retrieve it from the database and compare it to another xml file. 目的是确定需要哪个xml文件进行比较,以从数据库中检索该文件并将其与另一个xml文件进行比较。

Heres one thing I've been trying: 这是我一直在尝试的一件事:

                **//************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);

                    }

               }

Example print out using var dump of the content, just a snippet full print out is too long. 示例使用内容的var dump打印出来,只是完整打印出来的片段太长。 This should be in xml format. 这应该是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 File that I will be comparing against Sample code: 我将与示例代码进行比较的XML文件:

How it is printed in comparison: 比较如何打印:

$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 ) )

I managed to fix my problem by: 我设法通过以下方法解决了问题:

$xml = simplexml_load_string($finalModelToCompareTo);

The XML seems to have been converted to string within the blob and you need to use this method to convert it back to a SimpleXMLObject again. XML似乎已在blob中转换为字符串,您需要使用此方法再次将其转换回SimpleXMLObject

I think it really IS a XML file. 我认为它确实是XML文件。 The string(15513) " G title sub title 0 En... representation is the same XML file parsed by the browser and you only see the plaintext values but not the XML tags. So, don't worry about the losses you see in the printout. If you open up the webpage source using Ctrl+U you can see the complete XML file syntax. string(15513) " G title sub title 0 En...表示形式是浏览器解析的相同XML文件,并且您仅看到纯文本值,而不是XML标记。因此,不必担心在Windows中看到的损失如果使用Ctrl + U打开网页源,则可以看到完整的XML文件语法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM