process XMLHTTP response returning poorly formed html

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dandiebolt@yahoo.com

    #1

    process XMLHTTP response returning poorly formed html

    Using xmlhttp I am accessing a document from the web that is not xml
    and is in fact not even proper html even though it is supposed to be
    (unbalanced tags). Here is the type of code I am using:

    url="http://www.domain.com/page.html";
    var xmlhttp = new ActiveXObject(" Msxml2.XMLHTTP" );
    xmlhttp.open("G ET", url, false);
    xmlhttp.send();
    var xmlResp = xmlhttp.respons eXML;

    I want to create an array that holds the contents of every paragraph
    <P> tag. The paragraphs are well formed with both opening and closing
    tags <P> and </P> but the document as a whole is not valid xml or html.
    How can I process the so-called xml response to extract the contents of
    each paragraph into a unique element of the array? I would like to use
    DOM methods to extract the paragraphs rather than parse up the text
    with xmlhttp.respons eText. Any help would be appreciated.

  • strout

    #2
    Re: process XMLHTTP response returning poorly formed html

    It will be easy to parse by regular expression.

    Comment

    • dandiebolt@yahoo.com

      #3
      Re: process XMLHTTP response returning poorly formed html


      strout wrote:[color=blue]
      > It will be easy to parse by regular expression.[/color]

      How? The only think I know about the document is that the information I
      need is in between successive <P> and </P> tags. I was reluctant to
      use regexp because I have any more structure than what is described and
      I don't control the format of the page source.

      Comment

      • Tim Williams

        #4
        Re: process XMLHTTP response returning poorly formed html

        Why not automate IE to load the page and then grab your content once
        IE has done it's job ? Presumably that will "fix" any irregularities
        in the source.

        Depends on where you want to do this, but is an option. Or just use
        response.text and MSHTML ?

        Tim.


        <dandiebolt@yah oo.com> wrote in message
        news:1109358535 .357600.305490@ l41g2000cwc.goo glegroups.com.. .[color=blue]
        > Using xmlhttp I am accessing a document from the web that is not xml
        > and is in fact not even proper html even though it is supposed to be
        > (unbalanced tags). Here is the type of code I am using:
        >
        > url="http://www.domain.com/page.html";
        > var xmlhttp = new ActiveXObject(" Msxml2.XMLHTTP" );
        > xmlhttp.open("G ET", url, false);
        > xmlhttp.send();
        > var xmlResp = xmlhttp.respons eXML;
        >
        > I want to create an array that holds the contents of every paragraph
        > <P> tag. The paragraphs are well formed with both opening and
        > closing
        > tags <P> and </P> but the document as a whole is not valid xml or
        > html.
        > How can I process the so-called xml response to extract the contents
        > of
        > each paragraph into a unique element of the array? I would like to
        > use
        > DOM methods to extract the paragraphs rather than parse up the text
        > with xmlhttp.respons eText. Any help would be appreciated.
        >[/color]


        Comment

        • Jim Ley

          #5
          Re: process XMLHTTP response returning poorly formed html

          On 25 Feb 2005 11:08:55 -0800, dandiebolt@yaho o.com wrote:
          [color=blue]
          >Using xmlhttp I am accessing a document from the web that is not xml
          >and is in fact not even proper html even though it is supposed to be
          >(unbalanced tags).[/color]

          There's nothin inherent in unbalanced tags that would make something
          not valid HTML - html fullly allows lots of closing elements as
          optional.
          [color=blue]
          >How can I process the so-called xml response to extract the contents of
          >each paragraph into a unique element of the array? I would like to use
          >DOM methods to extract the paragraphs rather than parse up the text
          >with xmlhttp.respons eText. Any help would be appreciated.[/color]

          using the browser to parse the responseText as html will give you a
          DOM of it, there's no other reasonable solution.

          Jim.

          Comment

          • Mr.Clean

            #6
            Re: process XMLHTTP response returning poorly formed html

            >[color=blue][color=green]
            > >How can I process the so-called xml response to extract the contents of
            > >each paragraph into a unique element of the array? I would like to use
            > >DOM methods to extract the paragraphs rather than parse up the text
            > >with xmlhttp.respons eText. Any help would be appreciated.[/color]
            >
            > using the browser to parse the responseText as html will give you a
            > DOM of it, there's no other reasonable solution.[/color]

            You could also do it with just an IHTMLDocument2 implementaton, you
            don't really need the browser.

            Comment

            Working...