<p>I'm translating my C# code for YouTube video comments into PHP. In order to properly nest comment replies, I need to re-arrange XML nodes. In PHP I'm using DOMDocument and DOMXPath which closely corresponds to C# XmlDocument. I've gotten pretty far in my translation but now I'm stuck on getting the parent node of a DOMElement. A DOMElement does not have a parent_node() property, only a DOMNode provides that property.</p>

<p>After determining that a comment is a reply to a previous comment based in the string "in-reply-to" in a link element, I need to get its parent node in order to nest it beneath the comment it is in reply to:</p>

<pre><code>// Get the parent entry node of this link element
$importnode = $objReplyXML-&gt;importNode($link-&gt;parent_node(), true);
</code></pre>

[{'answer_id': 28944, 'author': 'Marius', 'author_id': 1585, 'author_profile': 'https://Stackoverflow.com/users/1585', 'pm_score': 5, 'selected': False, 'text': '<p><a href="http://no2.php.net/manual/en/class.domelement.php" rel="noreferrer">DOMElement</a> is a subclass of <a href="http://no2.php.net/manual/en/class.domnode.php" rel="noreferrer">DOMNode</a>, so it does have parent_node property. Just use $domNode->parentNode; to find the parent node.</p>\n\n<p>In your example, the parent node of $importnode is null, because it has been imported into the document, and therefore does not have a parent yet. You need to attach it to another element before it has a parent.</p>\n'}, {'answer_id': 28998, 'author': 'Marius', 'author_id': 1585, 'author_profile': 'https://Stackoverflow.com/users/1585', 'pm_score': 1, 'selected': False, 'text': "<p>I'm not entirely sure how your code works, but it seems like you have a small error in your code. </p>\n\n<p>On the line you posted in your question you have <code>$link-&gt;parent_node()</code>, but in the answer with the entire code snippet you have <code>$link**s**-&gt;parent_node()</code>. </p>\n\n<p>I don't think the <code>s</code> should be there. </p>\n\n<p><strong>Also, I think you should use $link->parentNode, not $link->parent_node().</strong></p>\n"}, {'answer_id': 49586651, 'author': 'Dimas Lanjaka', 'author_id': 6404439, 'author_profile': 'https://Stackoverflow.com/users/6404439', 'pm_score': 2, 'selected': False, 'text': '<p>Replace <code>parent_node()</code> to <code>parentNode</code></p>\n'}]
['https://Stackoverflow.com/questions/28878', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2601/']