xml - finding children in php simplexml xpath -
I'm running an xpath query on an xml stream and I am running a group of data again in it with the tag name Need to find. But I could not find the way to retrieve the tag name. XML stream is
& lt; Condition & gt; & Lt; Normal dataItmid = "Xovertemp-06" timestamp = "2011-09-02T03: 35: 34.535703Z" name = "xortemp" sequence = "24544" type = "templatelight" /> & Lt; General DataITMID = "ExServo-6" timestamp = "2011-09-02T03: 35: 34.535765Z" name = "xserve" sequence = "24545" type = "load" /> & lt; Normal dataItmid = "X-Travel-06" timestamp = "2011-09-02T03: 35: 34.535639Z" name = "extavel" sequence = "24543" type = "status" /> & Lt; / Status & gt; I'm trying to parse it as
temperature = normal load - normal , So what have I done ($ Xml- & gt; xpath ("// n: condition") - & gt; Children ("n") as $$) {echo $ child ["type"] "=" $ Baby & gt; GetName (); }
I am receiving the followin error
Fatal error: Members in a non-object member function in C: \ xampp \ < / Code> Now I know that the way I've got to do something with xpath or something else and I tried to add different combinations like adding a * query to slashes but every time Same error.
Not sure why you used name space in the first place (sample xml name is not in place )
In your xpath, you have to select all the condition / general tag, no condition tags you were doing ... In addition, < Code> xpath () returns a list, so foreach on it. You do not have to use it as children, as long as you do not want to parse children of $ child , this will mean, and it will work as expected. foreach ($ xml- & gt; xpath ("/ condition / general") $ $ as a child) {echo $ child ["type"] "=" $ $ of child ; GetName () "& Lt; br / & gt;"; } output
TEMPERATURE = normal load = normal condition = normal
Comments
Post a Comment