Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help PHP and XML!!

Status
Not open for further replies.

riddledaxis

Instructor
Jul 4, 2006
1
GB
Hi,

I am having a real nightmare working with XML data.

I have the following code in my site:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns=" >
<head>
<title>Checker</title>
</head>
<body>
<form style="WIDTH: 433px; HEIGHT: 540px" action=" method="get" name="ADSLChecker">
Telephone No
<input name="PhoneNo">
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>

The form works great, and returns a page with an XML Tree full of information but I cannot seem to work out how I can grab this XML data and display the sections that I need before it is displayed to the user.

I am probably missing something really obvious and any help will be greatly appreciated.

Thanks in advance.

PJ
 
you need to interpret the data. a good method is to use javascript to post your form data to the server, you can then grab the response and transform it or you can traverse the xml with javascript as well

Here's an example of posting the data from a form to a webservice then transforming the response with xsl

Code:
function postText(){
//this is the location of my local webservice
var url="[URL unfurl="true"]http://localhost:4244/WebSite2/hint.asmx/hint";[/URL]
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
xmlHttp.open('POST', url , true);
xmlHttp.setRequestHeader("Content-Type","application/x-[URL unfurl="true"]www-form-urlencoded");[/URL]
//one of the form values
var sendText=document.getElementById("Term").value
//this is where the form values are sent
xmlHttp.send("Term="+sendText);
xmlHttp.onreadystatechange = checkState;
 }
//this function ensures the xml is loaded
function checkState(){
  if(xmlHttp.readyState=="complete"||xmlHttp.readyState==4){
  Transform(xmlHttp.responseXML);
   }
//Here's the transform function which loads it against an 
//xml you could very well just use javascript to traverse 
//it as well but i tend to like xsl a bit more :) 
function Transform(xmlresponse){
// Load XML 
var xml = new ActiveXObject("Microsoft.XMLDOM")
xml.async = false
xml.load(xmlresponse)
// Load XSL
var xsl = new ActiveXObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load("hint.xsl")
// Transform and place in a div named suggested
document.getElementById("suggested").innerHTML =  xml.transformNode(xsl);
}

using this method you can grab the xml whether the form is submitted or not


MCP, .Net Solutions Development <%_%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top