I’m trying to construct an XML string to pass as the body of an HTTP request but I’m getting a bit stuck. Here’s the function that should build the string:
public function build_calendarquery()
{
$body = '<?xml version="1.0" encoding="utf-8" ?>
<C:'.$this->report_type.' xmlns:D="DAV:"
xmlns:C="urn:ietf:params:xml:ns:caldav">
<D:prop>
<D:getetag/>
<C:calendar-data>
<C:comp name="VCALENDAR">
<C:prop name="VERSION"/>
<C:comp name="VEVENT">';
foreach($this->cal_props as $prop)
{
$body .= '<C:prop name="'.strtoupper($prop).'" />';
}
$body .= '</C:comp>';
$body .= '<C:comp name="VTIMEZONE" />
</C:comp>
</C:calendar-data>
</D:prop>';
if($this->filters){
$body .= '<C:filter>
<C:comp-filter name="VCALENDAR">
<C:comp-filter name="VEVENT">';
foreach($this->filters as $filter=>$val)
{
$body .= '<C:'.$filter.' '.$val.'/>';
}
$body .= '</C:comp-filter>
</C:comp-filter>
</C:filter>';
}
$body .= '</C:calendar-query>';
return $body;
}
The problem I have is that when I try and use the data returned from this function there doesn’t seem to be anything there. What I mean is, if I write:
var_dump($this->build_calendarquery());
It returns NULL.
I’ve never really worked with XML before. Am I missing something really obvious?
So I tested your code locally and there is nothing wrong with the part you have provided.
outputs:
You will need to show us some more code. I’m interested as to where your
var_dump($this->build_calendarquery());statement is located.