How to Access XML attribute using SimpleXML in PHP -
I have an XML file like this and I want to get the value inside the property which is "1" PHP code? thank you in advanced.
& lt ;? XML version = "1.0" encoding = "UTF-8"? & Gt; & Lt; NodeInfo & gt; & Lt; Node flag = "128" & gt; & Lt; Address & gt; 18 F5 40 1 & lt; / Address & gt; & Lt; Name & gt; IMeterSolo & lt; / Name & gt; & Lt; Type & gt; 9.7.135.92 & lt; / Type & gt; & Lt; Enabled & gt; True & lt; / Enable & gt; & Lt; DeviceClass & gt; 0 & lt; / DeviceClass & gt; & Lt; Wattage & gt; 0 & lt; / Wattage capacity & gt; & Lt; DcPeriod & gt; 0 & lt; / DcPeriod & gt; & Lt; Pnode & gt; 18 F5 40 1 & lt; / Pnode & gt; & Lt; Property ID = "Scheduled Tribes" *** Value = "1" *** Formatted = "1" UOM = "W" /> & lt; / Node & gt; & Lt; Properties & gt; & Lt; Property ID = "Scheduled Tribes" value = "1" outline = "1" uum = "W" /> & Lt; Property ID = "TPW" value = "226" outline = "226" UOM = "KWS" /> & Lt; / Properties & gt; & Lt; / NodeInfo & gt;
$ string = '& lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; NodeInfo & gt; & Lt; Node flag = "128" & gt; & Lt; Address & gt; 18 F5 40 1 & lt; / Address & gt; & Lt; Name & gt; IMeterSolo & lt; / Name & gt; & Lt; Type & gt; 9.7.135.92 & lt; / Type & gt; & Lt; Enabled & gt; True & lt; / Enable & gt; & Lt; DeviceClass & gt; 0 & lt; / DeviceClass & gt; & Lt; Wattage & gt; 0 & lt; / Wattage capacity & gt; & Lt; DcPeriod & gt; 0 & lt; / DcPeriod & gt; & Lt; Pnode & gt; 18 F5 40 1 & lt; / Pnode & gt; & Lt; Property ID = "Scheduled Tribes" value = "1" outline = "1" uum = "W" /> & Lt; / Node & gt; & Lt; Properties & gt; & Lt; Property ID = "Scheduled Tribes" value = "1" outline = "1" uum = "W" /> & Lt; Property ID = "TPW" value = "226" outline = "226" UOM = "KWS" /> & Lt; / Properties & gt; & Lt; / NodeInfo & gt; '; $ Xml = simplexml_load_string ($ string); Ebb (string) $ xml- & gt; Node-> Properties-> Features () - & gt; Values. PHP_EOL; Foreign object ($ xml-> property-> property as $ element) {$ attr = $ element- & gt; Features (); Ebb (strings) $ attr- & gt; Values. PHP_EOL; }
Comments
Post a Comment