Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Dear All,

I am able to get the HTML content and store it in a variable called Content. Now I want to change the content of HTML using that variable rather than making changes in the existing variable as I have no access to that HTML file.

Below is my code :

<br />
<br />
Code behind: <br />
<br />
public string Content { get; set; }<br />
<br />
Matrix2CMSAPIWCFClient.MatrixCMSServiceSoapClient proxy = new Matrix2CMSAPIWCFClient.MatrixCMSServiceSoapClient();<br />
    			string jsonresp = proxy.GetWebsiteContent(<br />
    				Matrix2CMSAPIHelper.GenerateGetWebsiteContentRequest(<br />
    					username, password, DateTime.Now.ToString("yyMMddHHmmssff"), null,<br />
    					"cagecom/Customer-Service/FAQs"));<br />
    <br />
    			GetWebsiteContentResponse resp = Matrix2CMSAPIHelper.GenerateGetWebsiteContentReponse(jsonresp);<br />
    			if (resp.success)<br />
    			{<br />
    				Content = resp.content.contentHtml;<br />
        			}


HTML code:
XML
<div class="grid_10 CustServContent">
        <%=Content %>
    </div>

As you can see at the end of code behind, there is a variable called Content where I am reading and storing the HTML content. Please suggest me how do I modify HTML content like specifying a link in anchor tag, changing Div id, etc.,

Regards
Posted
Updated 19-Feb-14 21:42pm
v2

1 solution

Now that "Content" is a string and any HTML element can be identified by using regular expression as an HTML element would have a certain pattern in that string variable.

Example :
<br />
String Content = "<link type="text/css" rel="stylesheet" href="http://s.codeproject.com/App_Themes/CodeProject/Css/Main.min.css?dt=2.8.140216.1"><br />
<link type="text/css" rel="stylesheet" href="http://s.codeproject.com/App_Themes/CodeProject/CSS/jquery.autocomplete.min.css?dt=2.8.140216.1"><br />
"<br />


A link here is havng a patten as mentioned "<" followed by word "link" then some string and follwed by ">". You need to write regex to extract such matching and manipulate them.

Let me know if that helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900