将SimpleXML转换为DOMDocument,而不是DOMElement

时间:2022-10-20 18:40:45

I need to convert a SimpleXML object to a DOMDocument, to use it with DOMXPath. I need DOMXPath so that I can use its registerPHPFunctions method. Can this be done?

我需要将SimpleXML对象转换为DOMDocument,以便与DOMXPath一起使用。我需要DOMXPath,这样我就可以使用它的registerPHPFunctions方法。这个可以做吗?

With dom_import_simplexml I get a DOMElement, not DOMDocument.

使用dom_import_simplexml,我得到的是DOMElement,而不是DOMDocument。

2 个解决方案

#1


11  

You can fetch the document from $anyDOMNode->ownerDocument

您可以从$anyDOMNode->ownerDocument获取文档

#2


1  

$dom=new DOMDocument;
$dom->loadXML($sxml->asXML());

#1


11  

You can fetch the document from $anyDOMNode->ownerDocument

您可以从$anyDOMNode->ownerDocument获取文档

#2


1  

$dom=new DOMDocument;
$dom->loadXML($sxml->asXML());