How To Parse HTML Page in ASPX Page

A

Axel Dahmen

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
 
P

Phillip Ian

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
 
A

Axel Dahmen

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
 
J

Joerg Jooss

Axel said:
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,
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,135
Latest member
VeronaShap
Top