Parse NVD XML with PHP - php

I am trying to parse this XML file: http://static.nvd.nist.gov/feeds/xml/cve/nvdcve-2.0-modified.xml
<?xml version='1.0' encoding='UTF-8'?>
<nvd xmlns:cvss="http://scap.nist.gov/schema/cvss-v2/0.2" xmlns="http://scap.nist.gov/schema/feed/vulnerability/2.0" xmlns:vuln="http://scap.nist.gov/schema/vulnerability/0.4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:scap-core="http://scap.nist.gov/schema/scap-core/0.1" xmlns:cpe-lang="http://cpe.mitre.org/language/2.0" xmlns:patch="http://scap.nist.gov/schema/patch/0.1" nvd_xml_version="2.0" pub_date="2013-07-11T12:00:45" xsi:schemaLocation="http://scap.nist.gov/schema/patch/0.1 http://nvd.nist.gov/schema/patch_0.1.xsd http://scap.nist.gov/schema/scap-core/0.1 http://nvd.nist.gov/schema/scap-core_0.1.xsd http://scap.nist.gov/schema/feed/vulnerability/2.0 http://nvd.nist.gov/schema/nvd-cve-feed_2.0.xsd">
<entry id="CVE-2000-0851">
<vuln:vulnerable-configuration id="http://nvd.nist.gov/">
<cpe-lang:logical-test negate="false" operator="OR">
<cpe-lang:fact-ref name="cpe:/o:microsoft:windows_2000"/>
</cpe-lang:logical-test>
</vuln:vulnerable-configuration>
<vuln:vulnerable-software-list>
<vuln:product>cpe:/o:microsoft:windows_2000</vuln:product>
</vuln:vulnerable-software-list>
<vuln:cve-id>CVE-2000-0851</vuln:cve-id>
<vuln:published-datetime>2000-11-14T00:00:00.000-05:00</vuln:published-datetime>
<vuln:last-modified-datetime>2013-07-06T00:11:34.357-04:00</vuln:last-modified-datetime>
<vuln:cvss>
<cvss:base_metrics upgraded-from-version="1.0">
<cvss:score>4.6</cvss:score>
<cvss:access-vector>LOCAL</cvss:access-vector>
<cvss:access-complexity>LOW</cvss:access-complexity>
<cvss:authentication>NONE</cvss:authentication>
<cvss:confidentiality-impact>PARTIAL</cvss:confidentiality-impact>
<cvss:integrity-impact>PARTIAL</cvss:integrity-impact>
<cvss:availability-impact>PARTIAL</cvss:availability-impact>
<cvss:source>http://nvd.nist.gov</cvss:source>
<cvss:generated-on-datetime>2004-01-01T00:00:00.000-05:00</cvss:generated-on-datetime>
</cvss:base_metrics>
</vuln:cvss>
<vuln:security-protection>ALLOWS_OTHER_ACCESS</vuln:security-protection>
<vuln:references xml:lang="en" reference_type="VENDOR_ADVISORY">
<vuln:source>BID</vuln:source>
<vuln:reference href="http://www.securityfocus.com/bid/1651" xml:lang="en">1651</vuln:reference>
</vuln:references>
<vuln:references xml:lang="en" reference_type="UNKNOWN">
<vuln:source>MS</vuln:source>
<vuln:reference href="http://www.microsoft.com/technet/security/bulletin/ms00-065.asp" xml:lang="en">MS00-065</vuln:reference>
</vuln:references>
<vuln:references xml:lang="en" reference_type="UNKNOWN">
<vuln:source>ATSTAKE</vuln:source>
<vuln:reference href="http://www.atstake.com/research/advisories/2000/a090700-1.txt" xml:lang="en">A090700-1</vuln:reference>
</vuln:references>
<vuln:references xml:lang="en" reference_type="UNKNOWN">
<vuln:source>XF</vuln:source>
<vuln:reference href="http://xforce.iss.net/static/5203.php" xml:lang="en">w2k-still-image-service</vuln:reference>
</vuln:references>
<vuln:summary>Buffer overflow in the Still Image Service in Windows 2000 allows local users to gain additional privileges via a long WM_USER message, aka the "Still Image Service Privilege Escalation" vulnerability.</vuln:summary>
</entry>
<entry id="CVE-2004-0685">
...
I do the following
$url = 'http://static.nvd.nist.gov/feeds/xml/cve/nvdcve-2.0-modified.xml';
$source = file_get_contents($url);
$xml = new SimpleXMLElement($source);
If I echo the $source, then I see that the whole XML file has been loaded, but if I print_r $xml, only the id's are echo-ed:
SimpleXMLElement Object
(
[#attributes] => Array
(
[nvd_xml_version] => 2.0
[pub_date] => 2013-07-11T12:00:45
)
[entry] => Array
(
[0] => SimpleXMLElement Object
(
[#attributes] => Array
(
[id] => CVE-2000-0851
)
)
[1] => SimpleXMLElement Object
(
[#attributes] => Array
(
[id] => CVE-2004-0685
)
)
Why am I missing all the information in the "entry" tags

Maybe this could get you started:
<?php
$url = 'http://static.nvd.nist.gov/feeds/xml/cve/nvdcve-2.0-modified.xml';
$source = file_get_contents($url);
$xml = new SimpleXMLElement($source);
$entries = $xml->entry;
foreach ($entries as $entry) {
$namespace = $entry->getNameSpaces(true);
$tmp = $entry->children($namespace['vuln']);
//print_r($namespace);
print_r($tmp);
break;
}
Outputs:
SimpleXMLElement Object
(
[vulnerable-configuration] => SimpleXMLElement Object
(
)
[vulnerable-software-list] => SimpleXMLElement Object
(
[product] => cpe:/o:microsoft:windows_2000
)
[cve-id] => CVE-2000-0851
[published-datetime] => 2000-11-14T00:00:00.000-05:00
[last-modified-datetime] => 2013-07-06T00:11:34.357-04:00
[cvss] => SimpleXMLElement Object
(
)
[security-protection] => ALLOWS_OTHER_ACCESS
[references] => Array
(
[0] => SimpleXMLElement Object
(
[source] => BID
[reference] => 1651
)
[1] => SimpleXMLElement Object
(
[source] => MS
[reference] => MS00-065
)
[2] => SimpleXMLElement Object
(
[source] => ATSTAKE
[reference] => A090700-1
)
[3] => SimpleXMLElement Object
(
[source] => XF
[reference] => w2k-still-image-service
)
)
[summary] => Buffer overflow in the Still Image Service in Windows 2000 allows local users to gain additional privileges via a long WM_USER message, aka the "Still Image Service Privilege Escalation" vulnerability.
)
You can un-comment print_r($namespace), to see what the custom namespaces include.
If I do print out $namespace, the output is:
Array
(
[] => http://scap.nist.gov/schema/feed/vulnerability/2.0
[vuln] => http://scap.nist.gov/schema/vulnerability/0.4
[cpe-lang] => http://cpe.mitre.org/language/2.0
[cvss] => http://scap.nist.gov/schema/cvss-v2/0.2
[xml] => http://www.w3.org/XML/1998/namespace
)
Then to get vulnerable-configuration's attributes, simply use ->getAttribute('name')
An example of this would be:
print_r($tmp->{"vulnerable-configuration"}->attributes());
You should place the name in {} because it includes an invalid character.
The above should print out:
SimpleXMLElement Object
(
[#attributes] => Array
(
[id] => http://nvd.nist.gov/
)
)
If you don't know the values before hand, you can still loop through the $namespace variable:
foreach ($namespaces as $namespace) {
$tmp = $entry->children($namespace);
print_r($tmp);
}
The output of this would be:
SimpleXMLElement Object
(
)
SimpleXMLElement Object
(
[vulnerable-configuration] => SimpleXMLElement Object
(
)
[vulnerable-software-list] => SimpleXMLElement Object
(
[product] => cpe:/o:microsoft:windows_2000
)
[cve-id] => CVE-2000-0851
[published-datetime] => 2000-11-14T00:00:00.000-05:00
[last-modified-datetime] => 2013-07-06T00:11:34.357-04:00
[cvss] => SimpleXMLElement Object
(
)
[security-protection] => ALLOWS_OTHER_ACCESS
[references] => Array
(
[0] => SimpleXMLElement Object
(
[source] => BID
[reference] => 1651
)
[1] => SimpleXMLElement Object
(
[source] => MS
[reference] => MS00-065
)
[2] => SimpleXMLElement Object
(
[source] => ATSTAKE
[reference] => A090700-1
)
[3] => SimpleXMLElement Object
(
[source] => XF
[reference] => w2k-still-image-service
)
)
[summary] => Buffer overflow in the Still Image Service in Windows 2000 allows local users to gain additional privileges via a long WM_USER message, aka the "Still Image Service Privilege Escalation" vulnerability.
)
SimpleXMLElement Object
(
)
SimpleXMLElement Object
(
)
SimpleXMLElement Object
(
)

Related

Simplexml_load_string Entity parser error Start tag expected, '<' not found

I receive this warning when I try to get data from a call, I've tried with some solution for the same topic in stackoverflow but it doesn't work.
[2] simplexml_load_string(): Entity: line 4: parser error : Start tag expected, '<' not found
simplexml_load_string(): ^
the php code is as follow
$api = new MktApi();
$arr = array();
$xlm = $api->handleResponse($api->getBrands());
print_r($xlm);
$xml = simplexml_load_string($xlm);
and the print I have is like this
SimpleXMLElement Object ( [Head] => SimpleXMLElement Object ( [RequestId] => SimpleXMLElement Object ( ) [RequestAction] => GetBrands [ResponseType] => Brands [Timestamp] => 2017-05-04T16:29:44-0500 ) [Body] => SimpleXMLElement Object ( [Brands] => SimpleXMLElement Object ( [Brand] => Array ( [0] => SimpleXMLElement Object ( [BrandId] => 22912 [Name] => DC Comics [GlobalIdentifier] => 101020216193 ) [1] => SimpleXMLElement Object ( [BrandId] => 23324 [Name] => MIOS [GlobalIdentifier] => 101020216475 ) [2] => SimpleXMLElement Object ( [BrandId] => 32298 [Name] => 988 [GlobalIdentifier] => SimpleXMLElement Object ( ) ) [3] => SimpleXMLElement Object ( [BrandId] => 30015 [Name] => About Time [GlobalIdentifier] => SimpleXMLElement Object ( ) )
it's look like correct XML, I've tried to add the xml header but I still have the same issue.
It looks like $api->handleResponse(...) returns a SimpleXMLElement object. You don't need to parse it again.

SimpleXMLElement parsing issue with PHP

I'm trying to parse out the following response:
SimpleXMLElement Object (
[responseType] => SimpleXMLElement Object (
[inputConceptName] => aspirin [inputKindName] => % )
[groupConcepts] => SimpleXMLElement Object (
[concept] => Array (
[0] => SimpleXMLElement Object (
[conceptName] => ASPIRIN
[conceptNui] => N0000145918
[conceptKind] => DRUG_KIND )
[1] => SimpleXMLElement Object ( #
[conceptName] => Aspirin
[conceptNui] => N0000006582
[conceptKind] => INGREDIENT_KIND )
) ) )
in PHP. I have it stored as a curl string:
$xml = simplexml_load_string($data);
print_r($xml);
How do I get just the conceptNui of the first object as a PHP variable?
Take a look at the documentation, it give simple example to understand the friendly syntax to extract the data :
http://www.php.net/manual/en/simplexml.examples-basic.php
In your case, it could be :
$xml->groupConcepts->concept[0]->conceptNui
As your structure is
SimpleXMLElement Object (
[responseType] => SimpleXMLElement Object (
[inputConceptName] => aspirin
[inputKindName] => % )
[groupConcepts] => SimpleXMLElement Object (
[concept] => Array ([0] => SimpleXMLElement Object (
[conceptName] => ASPIRIN
[conceptNui] => N0000145918
[conceptKind] => DRUG_KIND )
[1] => SimpleXMLElement Object (
[conceptName] => Aspirin
[conceptNui] => N0000006582
[conceptKind] => INGREDIENT_KIND )
)
)
)
$conceptNui = $mainObj->groupConcepts->concept[0]->conceptNui;

SimpleXML data missing

I have a XML which I parse with php simpleXML.
The XML:
<GetOneGetAll DateTimeSystem="28-06-2011 17:19:29" RetCode="200" RetVal="1" RetMsg="User ok.">
<User Id="bc5cb4cf-19a6-4504-8e1a-f72dd97bcc66" ReferedConfirmedUsers="0" TotalRecomendations="0" DistinctRecomendations="0">
<Name>Name</Name>
<Surname>Surname</Surname>
<Gender>F</Gender>
<Email>email#email.com</Email>
<RefererCode>59286904</RefererCode>
<CustomPhotoMessage HasCustomPhoto="0" HasCustomMessage="0"/>
<ReferedConfirmedUsersList/>
</User>
</GetOneGetAll>
When I print_r the var using simpleXML I get:
SimpleXMLElement Object
(
[#attributes] => Array
(
[DateTimeSystem] => 28-06-2011 17:22:52
[RetCode] => 200
[RetVal] => 1
[RetMsg] => Login ok.
)
[User] => SimpleXMLElement Object
(
[#attributes] => Array
(
[Id] => bc5cb4cf-19a6-4504-8e1a-f72dd97bcc66
[ReferedConfirmedUsers] => 0
[TotalRecomendations] => 0
[DistinctRecomendations] => 0
)
[Name] => SimpleXMLElement Object
(
)
[Surname] => SimpleXMLElement Object
(
)
[Gender] => SimpleXMLElement Object
(
)
[Email] => SimpleXMLElement Object
(
)
[RefererCode] => SimpleXMLElement Object
(
)
[CustomPhotoMessage] => SimpleXMLElement Object
(
[#attributes] => Array
(
[HasCustomPhoto] => 0
[HasCustomMessage] => 0
)
)
[ReferedConfirmedUsersList] => SimpleXMLElement Object
(
)
)
)
Where is the data of Surname, Name, Email, Gender, etc.?
This is just a guess, but if you have xdebug installed, then the default recursion level of var_dump output is 3. This setting is xdebug.var_display_max_depth
You are using print_r, but some similar recursive limit could be being reached.

XPath string for all children of namespaced elements

Just getting started with XPath, and using it's implementation with PHP's SimpleXML objects. Right now I'm using //zuq:* to create an array of SimpleXML objects with the zuq prefix in a given document. However, I'd like the SimpleXML objects to reference all descendants regardless of namespace. I tried using //child::zuq:*, but the SimpleXML trees it creates don't seem to be complete.
Essentially, the objects captured should be all the top level objects of the zuq namespace throughout the document, containing all descendant elements regardless of namespace, including zuq.
tl;dr: How can I create a SimpleXML object tree from a given document where each SimpleXML root object is the highest level document element of a given namespace (such as zuq) containing all descendants of said element regardless of the descendant namespace? XPath is not a requisite but appears to be the best choice based on my reading.
test.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:zuq="http://localhost/zuq">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<h1>Heading</h1>
<p>Paragraph</p>
<zuq:region name="myRegion">
<div class="myClass">
<h1><zuq:data name="myDataHeading" /></h1>
<p>
<zuq:data name="myDataParagraph">
<zuq:format type="trim">
<zuq:param name="length" value="200" />
<zuq:param name="append">
<span class="paragraphTrimOverflow">...</span>
</zuq:param>
</zuq:format>
</zuq:data>
</p>
</div>
</zuq:region>
</body>
</html>
$sxml = simplexml_load_file('test.html');
$sxml_zuq = $sxml->xpath('//zuq:*/descendant-or-self::node()');
print_r($sxml_zuq);
Produces:
Array
(
[0] => SimpleXMLElement Object
(
[#attributes] => Array
(
[name] => myRegion
)
[div] => SimpleXMLElement Object
(
[#attributes] => Array
(
[class] => myClass
)
[h1] => SimpleXMLElement Object //I don't know why these don't contain their zuq descendants
(
)
[p] => SimpleXMLElement Object
(
)
)
)
[1] => SimpleXMLElement Object
(
[#attributes] => Array
(
[name] => myRegion
)
[div] => SimpleXMLElement Object
(
[#attributes] => Array
(
[class] => myClass
)
[h1] => SimpleXMLElement Object
(
)
[p] => SimpleXMLElement Object
(
)
)
)
[2] => SimpleXMLElement Object
(
[#attributes] => Array
(
[class] => myClass
)
[h1] => SimpleXMLElement Object
(
)
[p] => SimpleXMLElement Object
(
)
)
[3] => SimpleXMLElement Object
(
[#attributes] => Array
(
[class] => myClass
)
[h1] => SimpleXMLElement Object
(
)
[p] => SimpleXMLElement Object
(
)
)
[4] => SimpleXMLElement Object
(
)
[5] => SimpleXMLElement Object
(
[#attributes] => Array
(
[name] => myDataHeading
)
)
[6] => SimpleXMLElement Object
(
[#attributes] => Array
(
[class] => myClass
)
[h1] => SimpleXMLElement Object
(
)
[p] => SimpleXMLElement Object
(
)
)
[7] => SimpleXMLElement Object
(
)
[8] => SimpleXMLElement Object
(
)
[9] => SimpleXMLElement Object
(
[#attributes] => Array
(
[name] => myDataParagraph
)
)
[10] => SimpleXMLElement Object
(
[#attributes] => Array
(
[name] => myDataParagraph
)
)
[11] => SimpleXMLElement Object
(
[#attributes] => Array
(
[type] => trim
)
)
[12] => SimpleXMLElement Object
(
[#attributes] => Array
(
[type] => trim
)
)
[13] => SimpleXMLElement Object
(
[#attributes] => Array
(
[name] => length
[value] => 200
)
)
[14] => SimpleXMLElement Object
(
[#attributes] => Array
(
[type] => trim
)
)
[15] => SimpleXMLElement Object
(
[#attributes] => Array
(
[name] => append
)
[span] => ...
)
[16] => SimpleXMLElement Object
(
[#attributes] => Array
(
[name] => append
)
[span] => ...
)
[17] => SimpleXMLElement Object
(
[#attributes] => Array
(
[class] => paragraphTrimOverflow
)
[0] => ...
)
[18] => SimpleXMLElement Object
(
[#attributes] => Array
(
[class] => paragraphTrimOverflow
)
[0] => ...
)
[19] => SimpleXMLElement Object
(
[#attributes] => Array
(
[name] => append
)
[span] => ...
)
[20] => SimpleXMLElement Object
(
[#attributes] => Array
(
[type] => trim
)
)
[21] => SimpleXMLElement Object
(
[#attributes] => Array
(
[name] => myDataParagraph
)
)
[22] => SimpleXMLElement Object
(
)
[23] => SimpleXMLElement Object
(
[#attributes] => Array
(
[class] => myClass
)
[h1] => SimpleXMLElement Object
(
)
[p] => SimpleXMLElement Object
(
)
)
[24] => SimpleXMLElement Object
(
[#attributes] => Array
(
[name] => myRegion
)
[div] => SimpleXMLElement Object
(
[#attributes] => Array
(
[class] => myClass
)
[h1] => SimpleXMLElement Object
(
)
[p] => SimpleXMLElement Object
(
)
)
)
)
Don't trust the output of the print_r statement ... it seems to be showing an empty object, but in my testing the children are actually still there. For example, starting with your code above:
$sxml = simplexml_load_file('test.html');
$sxml_zuq = $sxml->xpath('//zuq:*/descendant-or-self::node()');
If I subsequently try a command like this:
print_r($sxml_zuq[0]->div->h1);
I get this output:
SimpleXMLElement Object
(
)
It seems to be empty, right? But if I modify the command to look like this:
echo $sxml_zuq[0]->div->h1->asXML();
I get the resultant tree with the namespaced child:
<h1><zuq:data name="myDataHeading"/></h1>
I'm not 100% sure why this is; it probably has something to do with the print_r statement trying to flatten the simplexml object and not dealing with the namespaces properly. But when you keep to the simplexml objects themselves that are returned from your xpath call, all of the children are preserved.
Now, in regards to your xpath itself, you probably DON'T want the "descendant-or-self" axis, because that will match not only the top-level zuq element, but also match all its children and create a larger array than you're actually seeking to return (unless I'm misunderstanding what you're asking). If you try something like this:
$sxml_zuq = $sxml->xpath('//zuq:*[not(ancestor::zuq:*)]');
then you'll get back an array of ONLY the top level of zuq namespaced elements. (while your example XML only had one such top-level element, your actual data may have several siblings at that level). You can then capture the content of each of these top level elements like this:
foreach ($sxml_zuq as $zuq_node) {
echo ($zuq_node->asXML());
}
Things get a little trickier if you want to repeat this process but do the search for top-level (or any) elements in the default namespace; you'd have to use the registerNamespace function to give the default namespace a temporary prefix, and do the xpath search on that.
I think you're looking for //zuq:*/descendant-or-self::*. This will result in all subtrees with the root having zuq namespace prefix.
The observed behavior seems to be an artifact of SimpleXML (the XPath specification does not deal with trees in the XPath query output, only separate nodes). You can probably solve it using something like
//zuq:*[not(ancestor::zuq:*)]/descendant-or-self::*
ancestor[...] checks whether there is an ancestor for which a condition is true - i.e. whether there is an ancestor with zuq prefix. So you should get only zuq: roots that have no zuq: ancestor.

Retrieving events from Google Calendar

I am trying to retrieve the XML data for Google Calendar. Authentication and retrieval all works. However, when I retrieve the events, gd: data isn't included as the protocol reference documents it would be (http://code.google.com/apis/calendar/data/2.0/developers_guide_protocol.html#RetrievingWithoutQuery)
Some error messages I'm running into depending on how I'm referencing the "when" node with attribute "startTime" (my ultimate goal in this anecdote) are as follows:
Fatal error: Call to a member function attributes() on a non-object in .../googlecalendarwrapper.php on line 226
when it looks like 'startTime'=> (string) $cal->when->attributes()->startTime,
GoogleCalendarWrapper_Model::getEventsList() [googlecalendarwrapper-model.geteventslist]: Node no longer exists when it looks like 'startTime'=> strval($cal->when->attributes()->startTime),
strval() [function.strval]: Node no longer exists when it looks like 'startTime'=> strval($cal->when->attributes()), and 'startTime'=> strval($cal->when->attributes('startTime')),
Code looks like:
$xml = new SimpleXMLElement($this->get($url, $header));
$calendars = array();
foreach ($xml->entry as $cal){
$calendars[] = array(
'id'=>strval($cal->id),
'published'=>strval($cal->published),
'updated'=>strval($cal->updated),
'title'=>strval($cal->title),
'content'=>strval($cal->content),
'link'=>strval($cal->link->attributes()->href),
'authorName'=>strval($cal->author->name),
'authorEmail'=>strval($cal->author->email),
'startTime'=> strval($cal->when->attributes()),
);
}
XML:
[0] => SimpleXMLElement Object
(
[id] => http://www.google.com/calendar/feeds/braden.keith%40smartersys.com/private/full/7li4mr2c81mub1hcoqktn73fbo
[published] => 2010-06-08T17:17:43.000Z
[updated] => 2010-06-08T17:17:43.000Z
[category] => SimpleXMLElement Object
(
[#attributes] => Array
(
[scheme] => http://schemas.google.com/g/2005#kind
[term] => http://schemas.google.com/g/2005#event
)
)
[title] => title
[content] => content
[link] => Array
(
[0] => SimpleXMLElement Object
(
[#attributes] => Array
(
[rel] => alternate
[type] => text/html
[href] => https://www.google.com/calendar/hosted/smartersys.com/event?eid=N2xpNG1yMmM4MW11YjFoY29xa3RuNzNmYm8gYnJhZGVuLmtlaXRoQHNtYXJ0ZXJzeXMuY29t
[title] => alternate
)
)
[1] => SimpleXMLElement Object
(
[#attributes] => Array
(
[rel] => self
[type] => application/atom+xml
[href] => https://www.google.com/calendar/feeds/braden.keith%40smartersys.com/private/full/7li4mr2c81mub1hcoqktn73fbo
)
)
[2] => SimpleXMLElement Object
(
[#attributes] => Array
(
[rel] => edit
[type] => application/atom+xml
[href] => https://www.google.com/calendar/feeds/braden.keith%40smartersys.com/private/full/7li4mr2c81mub1hcoqktn73fbo/63411700663
)
)
)
[author] => SimpleXMLElement Object
(
[name] => Braden Keith
[email] => braden.keith#smartersys.com
)
)
According to this article: http://www.sitepoint.com/blogs/2005/10/20/simplexml-and-namespaces/
You have to approach namespaces a tad differently with SimpleXMLElement. The solution is as follows:
$xml = new SimpleXMLElement($this->get($url, $header));
$xml->asXML();
$calendars = array();
foreach ($xml->entry as $cal){
$ns_gd = $cal->children('http://schemas.google.com/g/2005');
$calendars[] = array(
'id'=>strval($cal->id),
'published'=>strval($cal->published),
'updated'=>strval($cal->updated),
'title'=>strval($cal->title),
'content'=>strval($cal->content),
'link'=>strval($cal->link->attributes()->href),
'authorName'=>strval($cal->author->name),
'authorEmail'=>strval($cal->author->email),
'startTime'=> strval($ns_gd->when->attributes()->startTime),
);
}
Note the $ns_gd = $cal->children('http://schemas.google.com/g/2005'); - this defines the namespace. Then from there, $ns_gd->when->attributes()->startTime gets the attribute from gd:when named startTime.
Man it's been a bloody 2 days. But I figured it out. Hopefully this can help someone down the road.

Categories