php - Pass XML node as parameter on object instantiation and then calling subnodes from it -


I know that after passing the XML node and then using a method, it has a legal syntax in PHP. I tried to convert to string, but it was not working. What am I doing wrong? What would be the best / simple option?

XML

  & lt; Users & gt; & Lt; Widgets & gt; & Lt; Widgets & gt; Widget 1 & lt; / Widget & gt; & Lt; Accessories & gt; & Lt; Morestuff & gt; Things & lt; / Morestuff & gt; & Lt; / Luggage & gt; & Lt; Accessories & gt; & Lt; Morestuff & gt; Things & lt; / Morestuff & gt; & Lt; / Luggage & gt; & Lt; Widgets & gt; Widget 2 & lt; / Widget & gt; & Lt; / Widgets & gt; & Lt; / User & gt;  

PHP

  & lt ;? Php $ xmlfile = 'widgets / widgets_file / widgets Xml '; $ Widget = array (); $ User = New SimpleXMlelement ($ xmlfile, NULL, true); $ Dom = new DOMDocument ('1.0'); $ Dom- & gt; Protected WhiteSpace = false; $ Dom- & gt; FormatOutput = true; $ Dom = dom_import_simplexml ($ user) - & gt; Master document; Foreign currency ($ user- & gt; widget- & gt; widget as widget $) {$ new_widget = new widget ($ widget); // where the node has been passed the head_push ($ widgets, $ new_widget); } // for example $ new_widget [0] - & gt; Set_subnode (); $ New_widget [0] - & gt; Get_subnodes (); Classroom Widgets {Private $ widgets; Private $ luggage_array =); Public function __ composition ($ widget) {$ this- & gt; Widget = $ widget; } Public function set_subnodes () {foreach ($ this-> Widget-> Accessories- gt; morestuff as $ morestuff = & gt; $ value} {$ this- & gt; Accessories [$ morestuff] = $ Value;}} Public function get_subnodes () {foreach ($ this-> stuffArray $ as luggage) {echo $ stuff;}}}}  

It is possible to assign items as parameters to XML objects and call methods on them, but there are many errors in your code that are preventing it from working, especially XML, that you Use it There are no structures that you think it is - accessories and morestuff nodes do not have children in the widget , so among those tasks Anyone you are trying to perform with them will do the work. Here is a correct version of XML and some PHP code that I think you are trying to do above:

  $ widgets = array (); # You can load your code from a file, obviously - examples used For the masses, I am loading my $ function using $ sxe = simplexml_load_string (get_my_xml ()); Forex currency ($ sxe-> widget-> widgets as widget $) {$ new_widget = new widget ($ widget); // where the node has been passed the head_push ($ widgets, $ new_widget); } // foreach ($ w as $ widget) for example {$ w-> Set_subnodes (); $ W & gt; Get_subnodes (); } Get_my_xml () {return  

widget object:

  class widgets {personal $ widget; Private $ luggage_array =); Public function __ composition ($ widget) {$ this- & gt; Widget = $ widget; } Public function set_subnodes () $ stuffsArray foreach ($ this- & gt; Widget-> xpath ("luggage / more stuff") Put all "more" nodes in the form of $ ms {Print "Order at $ ms Array "PHP_EOL; Array_push ($ this-> General, $ MS);}} Public Function get_subnodes () {foreach ($ this-> stuffArray $ as luggage) {print" get_subnodes: running " $ Stuff "PHP_EOL;}}}  

Output:

: Getting things running_subnod Es: got two things on which the other two things of the widget are pushing the array into the array; Running_subnode: the widget is running two things: swoonode: other things found in widget two


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -