473,383 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

How to wrap HTML in XML and send it to a webcontrol??

I have a webservice which implements a webmethod called PrettyXML. This
webmethod loads an XML file and returns the XML, which is then displayed in
a webcontrol (textbox) on a webform.

If no XML file is found, it just returns null atm. I would now like to alter
it so that if the XML file is not found, some HTML is sent to the webcontrol
instead. The problem with this is that I cannot return Html because the
public method is XmlDocument, so I will have to wrap the Html inside of an
Xml tag for it to be able to return the data.

I need it to output something like this (so that the tags get encoded too):

<content>
this is html
&lt;BR&gt;
</content>

Here is my code so far:

[WebMethod()]
public XmlDocument getPrettyXML(string aFilename)
{

if (aFilename != null) {
FileInfo aFile = new FileInfo(Server.MapPath(aFilename));

if (aFile.Exists) {
// file exists - output XML
StringBuilder sb = new StringBuilder((int) aFile.Length*2);
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath(aFilename));
return doc;

} else {

// file does not exist - output some html

StringBuilder sb = new StringBuilder((int) 1000);

HtmlTextWriter writer = new HtmlTextWriter (new StringWriter(sb));

writer.Write("this is html");
writer.WriteLine();

// here I need to wrap the Html in Xml and return it

return sb.ToString(); // can't do this because the public
method is XmlDocument
}

}else{

return null;

}
}



StringBuilder sb = new StringBuilder();

WebUserControl1 myPortlet = new WebUserControl1();

StringWriter myStringWriter = new StringWriter(sb);

HtmlTextWriter myHtmlTextWriter = new
HtmlTextWriter((TextWriter)myStringWriter);

myPortlet.RenderControl(myHtmlTextWriter);


Nov 15 '05 #1
1 6004
You can create a new XML document without loading from file, use new nodes.
Populate them in your code at run tyme. Or better off, you can use a special
XML template that your XmlDoc will read in case file does not exist,
somethig like ErrorHTML.xml. this one you can build using XML editor.

"anthonysmales" <an******************@nospam.com> wrote in message
news:vj************@corp.supernews.com...
I have a webservice which implements a webmethod called PrettyXML. This
webmethod loads an XML file and returns the XML, which is then displayed in a webcontrol (textbox) on a webform.

If no XML file is found, it just returns null atm. I would now like to alter it so that if the XML file is not found, some HTML is sent to the webcontrol instead. The problem with this is that I cannot return Html because the
public method is XmlDocument, so I will have to wrap the Html inside of an
Xml tag for it to be able to return the data.

I need it to output something like this (so that the tags get encoded too):
<content>
this is html
&lt;BR&gt;
</content>

Here is my code so far:

[WebMethod()]
public XmlDocument getPrettyXML(string aFilename)
{

if (aFilename != null) {
FileInfo aFile = new FileInfo(Server.MapPath(aFilename));

if (aFile.Exists) {
// file exists - output XML
StringBuilder sb = new StringBuilder((int) aFile.Length*2);
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath(aFilename));
return doc;

} else {

// file does not exist - output some html

StringBuilder sb = new StringBuilder((int) 1000);

HtmlTextWriter writer = new HtmlTextWriter (new StringWriter(sb));

writer.Write("this is html");
writer.WriteLine();

// here I need to wrap the Html in Xml and return it

return sb.ToString(); // can't do this because the public
method is XmlDocument
}

}else{

return null;

}
}



StringBuilder sb = new StringBuilder();

WebUserControl1 myPortlet = new WebUserControl1();

StringWriter myStringWriter = new StringWriter(sb);

HtmlTextWriter myHtmlTextWriter = new
HtmlTextWriter((TextWriter)myStringWriter);

myPortlet.RenderControl(myHtmlTextWriter);



Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Filip Wtterwulghe | last post by:
Hello, We have a number of VB6 ActiveX applicationmodule(s) that are loaded into a IE6 WebBrowserControl . This WebControl is imbededded into Application X . Now We want to send a message from...
1
by: Simon Wigzell | last post by:
I send HTML formatted emails with links and images in them generated by my asp driven website. Occasionally the image will not appear and the link will not work. By looking at the email at the...
2
by: ViperDK | last post by:
What is the best way for that? I store all Data in the original form in the Database. To prevent output fields (especially the fields everyone can use) to do bad things like killing the...
17
by: Lloyd Sheen | last post by:
This IDE is driving me nuts. I needed another button so I copied an existing one, changed the Text and the id and position by drag and drop. Well then I run and get the following: Control...
4
by: Justin | last post by:
I have a fairly large piece of html, about 50 lines that I would like to send via an ASP.NET page I was wondering what would be the best and cleanest way to do this? Is there a way I can put the...
3
by: Sabri AKIN | last post by:
Hi, I want to send ascx file's html code as email.this ascx file is summary of customer sale.and at last iwant to send email to customer.how can i get and past ascx file's html code to mail body.
5
by: serge calderara | last post by:
Dear all, I am new in asp.net and prepare myself for exam I still have dificulties to understand the difference between server control and HTML control. Okey things whcih are clear are the fact...
3
by: Carl Gilbert | last post by:
Hi I have a Windows WebControl on my form and I plan to burn the application to a CD. The applcation has to navigate to a page that I am keeping in the root of the CD. I have put the page I...
2
by: Yeah | last post by:
Hi, all! I have a question. I am designing a listing similar to a phone book in HTML. Each listing has periods following it, but they must extend to the end of the table cell, and not wrap. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.