How To Parse HTML Page in ASPX Page

Discussion in 'ASP .Net' started by Axel Dahmen, Jul 29, 2005.

  1. Axel Dahmen

    Axel Dahmen Guest

    Hi,

    in order to add user dependant style sheets to my HTML pages I'd like to
    create an ASPX wrapper page which reads an HTML page, adds a currently
    selected style sheet and then outputs the rest of the page.

    But I couldn't find any class helping me to read HTML as a string enabling
    me to parse it and to search in it for the header section to inject my style
    element. Using HttpWebRequest seems quite awkward to me.

    Can someone please enlighten me on how this can be done? Plus I don't want
    to assume a particular encoding to my HTML pages. The method supposed should
    have no problems with varying HTML encoding (UTF8 etc.).

    TIA!
    Axel Dahmen
    Axel Dahmen, Jul 29, 2005
    #1
    1. Advertising

  2. Axel Dahmen

    Phillip Ian Guest

    I haven't tried this, so I'm not sure it would work, but couldn't you
    use an aspx page to return the CSS? Something like

    <LINK href="http://yourdomain.com/getCSSforUser.aspx?id=15"
    type=text/css rel=stylesheet>

    Then return a CSS file isntead of a page, much like one would use an
    aspx page to return a jpg image from a database?

    That way, your pages stay constant...no need to inject stuff on the
    fly.

    Just a thought.

    -Phil
    Phillip Ian, Jul 29, 2005
    #2
    1. Advertising

  3. Axel Dahmen

    Axel Dahmen Guest

    Well, Phil, you've brought me to an idea! Tnx! :)

    Yet there's one thing still being on my mind... I want editors (members of
    the staff) to create HTML pages. Each of these HTML pages must contain the
    same "fringe" mark-up, i.e. header and footer (like "Return to Homepage").
    But I don't want to rely on the editors to add this "must-have" mark-up. I'd
    prefer to have this more or less static addition being done automatically on
    rendering. But I can't have them create .aspx pages because they don't have
    the right software.

    My idea was to have them create a "root" document just containing their
    content and then to add all the necessary navigation stuff by ASP.NET.

    Do you perhaps have an idea on that?

    TIA!
    Best regards,
    Axel Dahmen


    -----------------
    "Phillip Ian" <> schrieb im Newsbeitrag
    news:...
    > I haven't tried this, so I'm not sure it would work, but couldn't you
    > use an aspx page to return the CSS? Something like
    >
    > <LINK href="http://yourdomain.com/getCSSforUser.aspx?id=15"
    > type=text/css rel=stylesheet>
    >
    > Then return a CSS file isntead of a page, much like one would use an
    > aspx page to return a jpg image from a database?
    >
    > That way, your pages stay constant...no need to inject stuff on the
    > fly.
    >
    > Just a thought.
    >
    > -Phil
    >
    Axel Dahmen, Jul 30, 2005
    #3
  4. Axel Dahmen

    Joerg Jooss Guest

    Axel Dahmen wrote:

    > Hi,
    >
    > in order to add user dependant style sheets to my HTML pages I'd like
    > to create an ASPX wrapper page which reads an HTML page, adds a
    > currently selected style sheet and then outputs the rest of the page.
    >
    > But I couldn't find any class helping me to read HTML as a string
    > enabling me to parse it and to search in it for the header section to
    > inject my style element. Using HttpWebRequest seems quite awkward to
    > me.


    There are at least two solutions I know of: Chris Lovett's SgmlReader
    on GotDotNet, and the HTML agility pack. Google for either of them.

    > Can someone please enlighten me on how this can be done? Plus I don't
    > want to assume a particular encoding to my HTML pages. The method
    > supposed should have no problems with varying HTML encoding (UTF8
    > etc.).


    That's not always possible. Some sites give no indication of what
    encoding is to be used whatsoever, so all that you can do is guess --
    though ISO-8859-1 is a good educated guess ;-)

    Cheers,
    --
    http://www.joergjooss.de
    mailto:
    Joerg Jooss, Jul 31, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mr. x
    Replies:
    1
    Views:
    1,965
    John Timney \(Microsoft MVP\)
    Nov 30, 2003
  2. John M
    Replies:
    1
    Views:
    1,133
    Kumar Reddi
    May 29, 2005
  3. asahin

    build control tree, parse aspx page

    asahin, Sep 2, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    1,125
    asahin
    Sep 2, 2005
  4. Replies:
    19
    Views:
    1,120
    Daniel Vallstrom
    Mar 15, 2005
  5. 7stud --

    optparse: parse v. parse! ??

    7stud --, Feb 20, 2008, in forum: Ruby
    Replies:
    3
    Views:
    183
    7stud --
    Feb 20, 2008
Loading...

Share This Page