Skip to content

Can't use xpath with comments in SimpleXML #12170

Description

@ndossche

Description

The following code:

<?php
$sxe = simplexml_load_string(<<<XML
<?xml version="1.0"?>
<container>
    <!-- comment -->
</container>
XML);

var_dump($sxe->xpath("//comment()"));

Resulted in this output:

array(0) {
}

But I expected this output instead:

array(1) {
[0] => the comment node
}

However, you can see the comment node with var_dump($sxe):

object(SimpleXMLElement)#1 (1) {
  ["comment"]=>
  object(SimpleXMLElement)#2 (0) {
  }
}

So SimpleXML can handle it, kinda.

PHP Version

PHP 8.1+

Operating System

Linux

Activity

  1. added a commit that references this issue on Sep 11, 2023
    7db9570
  2. added 3 commits that reference this issue on Sep 14, 2023
    b3bce23
    60b1673
    e5252a3
  3. added a commit that references this issue on Jan 31, 2024
    747335f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions