Jump to content

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/234975-parse-xml-and-get-node-names/
Share on other sites

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. 

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?)

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. 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.