簡體   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

我目前有一個數據庫,其中包含以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 dump打印出來,只是完整打印出來的片段太長。 這應該是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 ) )

我設法通過以下方法解決了問題:

$xml = simplexml_load_string($finalModelToCompareTo);

XML似乎已在blob中轉換為字符串,您需要使用此方法再次將其轉換回SimpleXMLObject

我認為它確實是XML文件。 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