I have an xml stored in a variable. If I load it in a domdocument as HTML: $DDoc->loadHTML($xml); I can get elements by an xpath query, but if I instead load it as XML my xpath queries stop working: $DDoc = new DOMDocument(); $DDoc->loadXML($xml); $xpath = new DOMXPath($DDoc); $query = "//li[@week=".$i."]"; $topics = $xpath->query($query); I've checked that the xml is well formated, no error or warning is displayed. $topics is just empty. Do anyone know why this could happen? Thank you for your attention.