jcanker Posted April 28, 2011 Share Posted April 28, 2011 How would you step through returned XML and retrieve all the node names and values if you don't know the XML structure? It seems to me like this shouldn't be complicated, but I'm beating my head against a wall trying to get it to work. I'd post up code, but I've tried so many things that I have no clue if any of them are even close. In short, I'm trying to build a web-based command-line interface for a MySQL server. I know the 1st and 2nd tier nodes, but I essentially need to be able to grab table/column names and values. This interface is for very beginning students to get a flavor of working with mySQL on my isolated DB server rather than install the mysql client on 30 pcs in the lab (and having to jump through all the hoops on getting the school's IT folk to *let* me install it. Please do not tell me to just find nodes by name: the problem is that each student will have their own table/column designs and this interface can't be trained to look for specific columns/XML nodes aside from the high-level schema. Here's an example of the XML returned by the query, "select * from users" I need to be able to loop through the child nodes of the "resource" node, retrieving the node names and values for them all. <?xml version="1.0" ?> - <returnedData> - <errors> <errno>0</errno> <error /> </errors> <returnType>resource</returnType> <numRows /> - <resource> <username>brad</username> <password>What?</password> </resource> - <resource> <username>mary</username> <password>hello</password> </resource> </returnedData> Quote Link to comment https://forums.phpfreaks.com/topic/234975-parse-xml-and-get-node-names/ Share on other sites More sharing options...
JKG Posted April 28, 2011 Share Posted April 28, 2011 do you have to use js? Quote Link to comment https://forums.phpfreaks.com/topic/234975-parse-xml-and-get-node-names/#findComment-1207558 Share on other sites More sharing options...
jcanker Posted April 28, 2011 Author Share Posted April 28, 2011 I've used jquery/AJAX to build everything out up to this point. If there's something else that will fix it, I'll take all suggestions at this point. I'm really spinning my wheels. The main requirement is that once I get the node names and node values, I need to be able to place that info inside of an existing div that's acting as the feedback for success/failure of the query and shows the returned data. Quote Link to comment https://forums.phpfreaks.com/topic/234975-parse-xml-and-get-node-names/#findComment-1207563 Share on other sites More sharing options...
JKG Posted April 28, 2011 Share Posted April 28, 2011 yeah, i know how to parse xml with php. look to http://www.w3schools.com/PHP/php_xml_simplexml.asp <?php $xdoc = new DomDocument; $xdoc->Load('http://www.petrolprices.com/feeds/averages.xml'); $unleaded = $xdoc->getElementsByTagName('Average')->item(1); $diesel = $xdoc->getElementsByTagName('Average')->item(4); ?> or you can grab via node number like i did here with petrol prices... (ps can you take a look at my question regarding showorhide?) Quote Link to comment https://forums.phpfreaks.com/topic/234975-parse-xml-and-get-node-names/#findComment-1207573 Share on other sites More sharing options...
jcanker Posted April 28, 2011 Author Share Posted April 28, 2011 Let me clarify: The xml is being generated by php and sent over to the html via AJAX. I can't use php as I don't want the page reloading every time a new SQL command is entered. I'll take a look at the show/hide ? Quote Link to comment https://forums.phpfreaks.com/topic/234975-parse-xml-and-get-node-names/#findComment-1207576 Share on other sites More sharing options...
salathe Posted April 28, 2011 Share Posted April 28, 2011 Are you using one of the JavaScript frameworks? jQuery makes working with XML fairly painless, plain-old JavaScript is more of a pain. Quote Link to comment https://forums.phpfreaks.com/topic/234975-parse-xml-and-get-node-names/#findComment-1207581 Share on other sites More sharing options...
jcanker Posted April 28, 2011 Author Share Posted April 28, 2011 I'd much rather work with jQuery, but I'm having difficulty getting the node names out from the schema. In my other projects I can use $(xml).find('specificNode') since I know what I'm looking for. Here, I have to read the schema so the students can use whatever table structure they want in their intro exercises. Quote Link to comment https://forums.phpfreaks.com/topic/234975-parse-xml-and-get-node-names/#findComment-1207587 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.