user978122
user978122

Reputation: 5761

Escape characters for PHP & SimpleXML

For the life of me, I cannot find any information how to use SimpleXML to parse with special characters.

I have some XML I am trying to parse, but PHP obviously doesn't like it:

<?xml version="1.0" encoding="UTF-8"?>
<calendar-multiget xmlns:D="DAV:" xmlns="urn:ietf:params:xml:ns:caldav">
  <D:prop>
    <D:getetag/>
    <calendar-data/>
  </D:prop>
  <D:href>/davical/caldav.php/rwr26/home/c9bfc6b0-064e-4316-83fe-753db34e67ee.ics</D:href>
  <D:href>/davical/caldav.php/rwr26/home/4e6e3500e89673.63357057.ics</D:href>
  <D:href>/davical/caldav.php/rwr26/home/4e6e42d394f9e5.08299254.ics</D:href>
</calendar-multiget>

I can't do $D:href = new SimpleXMLElement($xmlstr);. And XPath isn't happy with that either, assuming I am doing this correctly. Can anyone point out what I am doing wrong here?

Upvotes: 1

Views: 2213

Answers (2)

brian_d
brian_d

Reputation: 11395

Register the namespace with XPath registerXPathNamespace

Upvotes: 1

dlamblin
dlamblin

Reputation: 45361

If you look at the basics, you'll see that putting a colon inside the variable name is not valid. But perhaps if you showed a little more we'd get a better picture of what's not working.

Upvotes: 1

Related Questions