Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试从数据库中提取存储为blob的xml文件,并将提取的xml数据存储在php对象中_Php_Xml - Fatal编程技术网

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

尝试从数据库中提取存储为blob的xml文件,并将提取的xml数据存储在php对象中,php,xml,Php,Xml,我目前有一个数据库,其中包含存储为blob的xml文件。当我尝试使用sql提取这些数据时,我并没有获得原始xml格式的数据,而只是从xml文件中获取一些文本。我已经尝试了很多方法,但到目前为止没有运气。有人对如何做到这一点有任何想法吗 其目的是确定需要哪个xml文件进行比较,从数据库中检索该文件并将其与另一个xml文件进行比较 有一件事我一直在尝试: **//************THIS IS WHERE THE PROBLEM IS*************

我目前有一个数据库,其中包含存储为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文件。
字符串(15513)“G title sub title 0 En…
表示是浏览器解析的同一个XML文件,您只看到纯文本值,而看不到XML标记。所以,不要担心在打印输出中看到的损失。如果您使用Ctrl+U打开网页源代码,您可以看到完整的XML文件语法。

上面的代码可能太多了。请提供一个(M代表最小值)。很抱歉,问题代码更新得更好:)还请向我们展示“xml文件中的文本位”是什么样的,例如,
var_dump($row['content'])的摘录。
突出显示与最初插入的文本相比的可疑位。顺便说一句,如果在浏览器中读取字符串,请记住浏览器将尝试将字符串解释为HTML,从而有效地隐藏(实际上)所有XML标记。直接查看HTML源代码(在大多数浏览器中为CTRL+U)。