As John noted at the end... I do not have control over the format of the XML... but thanks.... I will try... BTW i am using PHP4 is SimpleXML able to be used and if so how?
Sorry for the newbie question On Thu, 23 Sep 2004 10:44:31 -0400, John Holmes <[EMAIL PROTECTED]> wrote: > From: "GH" <[EMAIL PROTECTED]> > > >> I am new to php and xml and would like to know how I can set a > >> variable (i.e $terror_threat_level) equal to the value of > >> Threat_Advisory's Condition in the following that is available at > >> http://www.dhs.gov/dhspublic/getAdvisoryCondition ... > >> > >> <?xml version="1.0" encoding="UTF-8" ?> > >> <THREAT_ADVISORY CONDITION="ELEVATED" /> > > Hmmm... I couldn't get SimpleXML to work with this data; maybe it doesn't > pick up attributes or that XML could be better formed??? > > I'm sure there's an XML way to do it, but if you don't find anything, here's > a quick way to match it with regular expressions. > > <? > $str = > file_get_contents('http://www.dhs.gov/dhspublic/getAdvisoryCondition'); > preg_match('/CONDITION="([^"]+)"/',$str,$match); > echo $match[1]; > ?> > > Off topic, I was thinking this XML would be "better formed" XML as: > > <THREAT_ADVISORY_CONDITION>ELEVATED</THREAT_ADVISORY_CONDITION> > > and then you can use: > > $str = > file_get_contents('http://www.dhs.gov/dhspublic/getAdvisoryCondition'); > $xml = simplexml_load_string($str); > > but simplexml simply has one element, [0] => ELEVATED. You can't do $xml[0] > or $xml->0 (since $xml is an object), etc and you have to do > > $threat = current($xml); > echo $threat; > > You can cast $xml to an array, but that still doesn't seem very intuitive: > > $a = (array)$xml; > echo $a[0]; > > I'm not an XML wiz by any means... is this just bad XML that SimpleXML is > handling the best it can or is SimpleXML acting up?? If it's bad XML put out > by DHS, then I can pass some messages up the chain... :) > > ---John Holmes... > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php