Re: Assigning contents within HTML tag to string variable.

From: Bill Mild (BillMild_at_discussions.microsoft.com)
Date: 08/06/04


Date: Fri, 6 Aug 2004 13:23:01 -0700

Sorry Ken for the delay, but for some reason, the msdn website was not
letting me post yesterday and I kept getting an error from the newsgroup
website. This is is Page_Load...

string filepath = Server.MapPath("../AboutUs/index.aspx");
//XmlDocument xmldoc = new XmlDocument();
//xmldoc.LoadXml(filepath);
StreamReader sr = new StreamReader(filepath);
string fileContents = sr.ReadToEnd();

You see that I have the xml lines commented out. I'm reading the actual
file into a string variable named fileContents. I just want to truncate the
string to a subset which includes the contents of <div id="content">. Or,
alternately, I could use ideas for transforming this string into well-formed
xml which I could load into an xml document using the commented out lines
above. Presently, if I uncomment those lines, I get an error that is is not
well-formed xml. Either approach would be fine.

"Ken Cox [Microsoft MVP]" wrote:

> Hi Bill,
>
> Could you clarify what you mean by assign it to a string variable? Are you
> trying to insert the DIV content from the code-behind?
>
> A literal control will hold that kind of content if that's what you need.
>
> Ken
>
> "Bill Mild" <Bill Mild@discussions.microsoft.com> wrote in message
> news:064C93C2-E361-4DD5-B509-22160FBD3F6B@microsoft.com...
> >I have an aspx web form below. I would like to grab the contents within
> >the <div id="content"> tag and assign it to a string variable. This is not
> >well-formed XML so I can't use XML, unless there is a simple way to turn
> >this into well-formed XML. I need some ideas. Thanks, William Mild
> >
> > <%@ Page language="c#" Codebehind="index.aspx.cs" AutoEventWireup="false"
> > Inherits="vna.AboutUs.index" %>
> > <%@ Register TagPrefix="wilson" Namespace="Wilson.MasterPages"
> > Assembly="WilsonMasterPages" %>
> > <wilson:masterpage id="MPContainer" runat="server"
> > TemplateFile="../Template.ascx">
> > <DIV id="crumb"><IMG id="Img1" src="~/images/child_04.jpg" border="0"
> > name="child_04" runat="server"></DIV>
> > <DIV id="subsectionheader">About Us</DIV>
> > <DIV id="sectionImage"><IMG id="Img2" src="~/images/aboutus.jpg"
> > runat="server"></DIV>
> > <Div id="content">
> >
> > <P>We work closely with your physician to plan for and provide the
> > services you
> > need to get better at home. Our expert staff of nurses, plus physical,
> > occupational and speech therapists is available to you as necessary. We
> > also
> > offer maternal/child health, pediatric care, wound care, medical social
> > services, nutritional counseling and are able to provide home health aides
> > to
> > assist you with personal, non-medical care. We will show you how to obtain
> > and
> > use any equipment or supplies your doctor may have prescribed and will
> > direct
> > you to appropriate community services for other types of support.
> > </P>
> >
> > <UL>
> > <LI>
> > You or your family
> > <LI>
> > Your physician
> > <LI>
> > Your case manager or health care professional
> > <LI>
> > A community agency
> > <LI>
> > A coordinator in a hospital or nursing facility
> > <LI>
> > An assisted living or rehabilitation facility
> > </LI>
> > </UL>
> > <P>When we receive the call, well start by talking with your physician
> > about you
> > and promptly set up a visit, so we can determine what we are able to do
> > for
> > you. It <EM>really </EM>is that simple!
> > </P>
> > <P>From the beginning, we involve you in your plan of care and, when
> > possible,
> > teach family members who want to participate in treatments or therapies.
> > Well
> > make a schedule of regular visits from our nurses and/or therapists, plus
> > we
> > are on call and available to you 24 hours a day, 7 days a week.
> > </P>
> > <P>Your goal is to be well and independent.
> > </P>
> > <P>Our goal is to get you there, in the comfort of your own home or
> > residence.
> > </P>
> > </Div>
> > <DIV id="subsectionfooter"><STRONG>Mission | <A
> > href="History.aspx">
> > History</A> | Accreditation </STRONG>
> > </DIV>
> > </wilson:masterpage>
> >
>
>



Relevant Pages