[RESOLVED] XMLHTTP.responseText and Javascript
Well, I'm using the XMLHTTP API (which is pretty useful!). :rolleyes:
Now that I returned the "xml string" from another website, how do I parse through that data to get the information that I need? I don't need the whole string!
So if my reponse: xmlhttp.responseText = <id value=1234><init>MPH</init></id><id value=1235><init>STP</init></id><id value=1236><init>RTY</init></id>
..how do move around the xml to retrieve id of 1236 which is RTY so I can name that tag on my page 'RTY'? :blush:
Are there any methods that I can use from the XMLHTTP API that I can use to retrieve that certain node in XML that I need? Or do I have to use Javascript to parse the data that I need? :sick:
The only examples I see don't parse through the xmlhttp.responseText, they use the whole damn XML string! :ehh:
I appreciate any help.
P.S. I suppose I would have to use a well-formed XML to do this correctly. :eek2:
Re: XMLHTTP.responseText and Javascript
I think I'm going to have to build a template of the XML data and then use object.indexOf(searchValue,[fromIndex]) method to pull the data out!!
This is going to suck especially since my javascript sucks too! HAHA! :eek:
Does anyone know a simple technique or ways to use the XMLHTTP object? :ehh:
Re: XMLHTTP.responseText and Javascript
I think I have a few of it down. :p
I changed my "called" web page so that it passed back a pipe delimited string, i.e '1234:MPH|1235:STP|1236:RTY'
I then used javascript to split the string into arrays, looped through the arrays and then used the document.getElementById method to change my main page information.
It took a while to realize I wouldn't have to use well-formed xml, but I found a solution. (Just because the API is called XMLHTTP does mean your return data has to be in XML format!) :wave:
Re: [RESOLVED] XMLHTTP.responseText and Javascript
when you use responseText method, then whether or not the return value is XML it will be regarded as text.
when you use responseXML and the site you have tried to access is set to return XML, then you can get the XML object.
Besides i think it is possible for you to parse the string returned by the site through your own XML object. Not sure of the particulars but i know it's doable.