作者:广东工业大学普通话_333 | 来源:互联网 | 2023-09-16 11:16
ImprettynewtoPHPXPathhere.ImusingSimpleXMLandXPathinPHP,traversingXMLwithnamespac
I'm pretty new to PHP/XPath here. I'm using SimpleXML and XPath in PHP, traversing XML with namespaces.
我对PHP/XPath非常熟悉。我在PHP中使用SimpleXML和XPath,使用名称空间遍历XML。
My question is concerning the 'prefix' parameter in the registerXPathNamespace function.
I have two xmlns in my xml feed; however, I'm uncertain as to how to use the function in this case.
When I run this code, I get the following error msg:
我的问题是关于registerXPathNamespace函数中的“前缀”参数。我的xml提要中有两个xmlns;但是,我不确定在这种情况下如何使用这个函数。当我运行这个代码时,我得到以下错误msg:
Undefined offset: 0
My XML cannot be changed in any way. Please see the code, below. Thanks for any leads.
我的XML不能以任何方式改变。请看下面的代码。谢谢你的任何线索。
PHP code:
PHP代码:
registerXPathNamespace('a','http://www.digitalmeasures.com/schema/data');//
//below, as the 'dmd' prefix is in the xml, I've included it here.
$simplexml->registerXPathNamespace('dmd','http://www.digitalmeasures.com/schema/data-metadata');
//
$myDataObjects2 = $simplexml->xpath('//Record/INTELLCONT[@id="14"]/CONTYPE')[0];
//$myDataObjects2 = $simplexml->xpath('//Record/INTELLCONT/CONTYPE')[0];
echo $myDataObjects2;
?>
The XML:
XML:
Author Content
Revised
Accepted
2 个解决方案