Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Re: data island creation using reponseText >Thread Next - Re: data island creation using reponseText Re: data island creation using reponseTextTo: NULL Date: 7/6/2007 4:46:00 PM
<clockemail@a...> wrote in message
news:1183733289.812247.279000@q......
> On Jul 6, 9:11 am, "Anthony Jones" <A...@yadayadayada.com> wrote:
> > <clockem...@alltel.net> wrote in message
> >
> > news:1183729025.181947.255570@g......
> >
> >
> >
> >
> >
> > > On Jul 6, 3:28 am, "Anthony Jones" <A...@yadayadayada.com> wrote:
> > > > <clockem...@alltel.net> wrote in message
> >
> > > >news:1183653614.908936.37170@n......
> >
> > > > > I welcome all suggestions as to how to solve the following
problem,
> > > > > and I am fully prepared for mountains of criticism!.
> >
> > > > > I am now prohibited from using XMLHttpRequest and template queries
to
> > > > > return data from an SQL database as I had previously done.
Therefore,
> > > > > I have been using an XMLHttpRequest to return the responseText of
an
> > > > > aspx page that adds the returned data to a blank page using
> > > > > Response.Write. The blank aspx page has the following XML added to
it
> > > > > by code.
> > > > > <xml>
> > > > > <loaninfo>
> > > > > <borrower>
> > > > > <firstname>John</firstname>
> > > > > <middlename>Fred</middlename>
> > > > > <lastname>Harris</lastname>
> > > > > </borrower>
> > > > > <borrower>
> > > > > <firstname>Frank</firstname>
> > > > > <middlename>Bob</middlename>
> > > > > <lastname>Smith</lastname>
> > > > > </borrower>
> > > > > </loaninfo>
> > > > > </xml>
> >
> > > > > I use the following JavaScript code to return this xml to the aspx
> > > > > page where it is needed. The aspx page has the following data
island
> > > > > included within the html.
> >
> > > > > <xml id="xmlDataIsland">
> > > > > </xml>
> >
> > > > > The http variable below has been properly set elsewhere in the
code. I
> > > > > am just trying to minimize the necessary code inclusion.
> >
> > > > > var url = "CreateXMLFile.aspx?strSearch=" + strSearchTerm;
> > > > > http.open("GET", url, true);
> > > > > http.onreadystatechange = handleHttpManualSearch;
> > > > > http.send(null);
> >
> > > > > function handleHttpManualSearch() {
> > > > > if (http.readyState == 4)
> > > > > {
> > > > > var strXML = http.responseText;
> > > > > document.getElementById("xmlDataIsland").InnerXml = strXML;
> > > > > alert("strXML = " +
> > > > > document.getElementById("xmlDataIsland").InnerXml);
> > > > > }
> >
> > > > > The alert displays the xml exactly as it appears on the aspx page
from
> > > > > which it was taken, including the <xml> tags. However, I have
failed
> > > > > to find a way to refer to elements within the data island (I have
also
> > > > > removed the <xml> tags from the responseText, which did not solve
the
> > > > > problem). Is there a way in which I can step through the borrower
> > > > > nodes to obtain the data contained within, and make use of it in
> > > > > JavaScript? I was looking for something similar to the way that I
> > > > > would handle a responseXML in the following manner.
> >
> > > > > var xmlDocument = http.responseXML;
> > > > > var root = xmlDocument.documentElement;
> > > > > if(root.getElementsByTagName('Message').length > 0)
> > > > > {
> > > > > var strMessage =
> > > > > root.getElementsByTagName('borrower').item(0).firstChild.data;
> > > > > }
> >
> > > > I'm a bit confused why you need to use data islands?
> > > > XMLHttpRequest has a ResponseXML property which will return an XML
DOM
> > when
> > > > the response content type is "text/xml".- Hide quoted text -
> >
> > > > - Show quoted text -
> >
> > > How can I set that in client-side JavaScript?
> >
> > You don't. You do it in the ASPX:- Response.ContentType = "text/xml"-
Hide quoted text -
> >
> > - Show quoted text -
>
> I'm obviously missing something, but I added that line after my
> Response.Write lines in the aspx page, and then restored my use of
> responseXML in my JavaScript, but that did not work. Thanks for your
> help Anthony, and I am probably not using the best way to solve this,
> but as I have it working I will settle for that for now.
>
If response bufffering is not enabled then setting the content type after
sending the content is too late.
Do it at the start of the page.
If you are include an <?xml declare at the top of the xml make sure that you
don't have any blank lines preceeding the xml either.
While you are at it make sure you get the character encoding correct by
setting the Response.CodePage = 65001 and adding Response.CharSet = "UTF-8"
to your code as well.
Don't just do it, do it right.
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
