473,654 Members | 3,108 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do you output XML from ASP.NET?

I am wondering how to make ASP.NET output XML instead of HTML.

Here is my situation:

I am using IE as a front-end to browse company documents. Let's say,
a user wants a Word document called foobar, then they'd do a http
request for "getdoc.aspx?fo obar"

Now what getdoc.aspx does is it gets the Word document from the server
file system, does an XSLT transform on it to hyperlink it to other
documents and then returns the hyperlinked WordML document to the
browser.

What I want is for the IE to display the transformed Word document in
the browser's Word Add-In.

My problem is that ASP.NET seems to want to return HTML, not XML/
WordML.

Using an XmlWriter I am able to stream the WordML markup to the
browser, but I get a DOCTYPE and HTML code appended to the end, so the
Word Add-In won't touch it.

I tried deleting the DOCTYPE and HTML markup from the page design
source in Visual Studio, but then VS complains "Validation (): Element
'html' occurs too few times".

I know I can transform the WordML into HTML using WordML2HTML.xsl t,
but this is both slow and not as pretty as loading a WordML into the
browser Add-In. (I want the client to deal with processing the WordML
tags.)

I know I could return XML via a WebService, but I don't want to deal
with the WSDL. All I want is for IIS to return the raw XML/WordML so
that the browser can load it.

Is there some special settings or DOCTYPE I need to set in Visual
Studio to get ASP to return XML or is a Web Form the wrong tool for
what I'm trying to do?

thanks
paul

May 17 '07 #1
10 54956
Hi,

It's pretty easy. You just need to set the right content type (text/xml) and
just pump out the XML. For a sample, look at the section "Emitting XML
Content to the Browser Window Directly" on
http://aspnet.4guysfromrolla.com/articles/092403-1.aspx

"li******@aol.c om" wrote:
I am wondering how to make ASP.NET output XML instead of HTML.

Here is my situation:

I am using IE as a front-end to browse company documents. Let's say,
a user wants a Word document called foobar, then they'd do a http
request for "getdoc.aspx?fo obar"

Now what getdoc.aspx does is it gets the Word document from the server
file system, does an XSLT transform on it to hyperlink it to other
documents and then returns the hyperlinked WordML document to the
browser.

What I want is for the IE to display the transformed Word document in
the browser's Word Add-In.

My problem is that ASP.NET seems to want to return HTML, not XML/
WordML.

Using an XmlWriter I am able to stream the WordML markup to the
browser, but I get a DOCTYPE and HTML code appended to the end, so the
Word Add-In won't touch it.

I tried deleting the DOCTYPE and HTML markup from the page design
source in Visual Studio, but then VS complains "Validation (): Element
'html' occurs too few times".

I know I can transform the WordML into HTML using WordML2HTML.xsl t,
but this is both slow and not as pretty as loading a WordML into the
browser Add-In. (I want the client to deal with processing the WordML
tags.)

I know I could return XML via a WebService, but I don't want to deal
with the WSDL. All I want is for IIS to return the raw XML/WordML so
that the browser can load it.

Is there some special settings or DOCTYPE I need to set in Visual
Studio to get ASP to return XML or is a Web Form the wrong tool for
what I'm trying to do?

thanks
paul

May 17 '07 #2
On May 17, 3:49 am, linha...@aol.co m wrote:
Using an XmlWriter I am able to stream the WordML markup to the
browser, but I get a DOCTYPE and HTML code appended to the end, so the
Word Add-In won't touch it.
Try to set Response.Conten tType

Response.Clear( );
Response.Conten tType = "text/xml";
Response.Write( xml);

May 17 '07 #3
Just a suggestion...in your Page_Load event, try adding this at the
top:

Response.Conten tType = "text/xml; charset=utf-8";

On May 16, 9:49 pm, linha...@aol.co m wrote:
I am wondering how to make ASP.NET output XML instead of HTML.

Here is my situation:

I am using IE as a front-end to browse company documents. Let's say,
a user wants a Word document called foobar, then they'd do a http
request for "getdoc.aspx?fo obar"

Now what getdoc.aspx does is it gets the Word document from the server
file system, does an XSLT transform on it to hyperlink it to other
documents and then returns the hyperlinked WordML document to the
browser.

What I want is for the IE to display the transformed Word document in
the browser's Word Add-In.

My problem is that ASP.NET seems to want to return HTML, not XML/
WordML.

Using an XmlWriter I am able to stream the WordML markup to the
browser, but I get a DOCTYPE and HTML code appended to the end, so the
Word Add-In won't touch it.

I tried deleting the DOCTYPE and HTML markup from the page design
source in Visual Studio, but then VS complains "Validation (): Element
'html' occurs too few times".

I know I can transform the WordML into HTML using WordML2HTML.xsl t,
but this is both slow and not as pretty as loading a WordML into the
browser Add-In. (I want the client to deal with processing the WordML
tags.)

I know I could return XML via a WebService, but I don't want to deal
with the WSDL. All I want is for IIS to return the raw XML/WordML so
that the browser can load it.

Is there some special settings or DOCTYPE I need to set in Visual
Studio to get ASP to return XML or is a Web Form the wrong tool for
what I'm trying to do?

thanks
paul

May 17 '07 #4
Thanks everyone somuch for the suggestions & links.

It's still not working. My code (which I adapted from an XSLT web
example) uses an Xmlwriter.Close () to output the xml to the response
stream. I guess I don't know how to use it with Response.Write. I'm
reading through the 4guysfromrolla example which uses XmlTextWriter
(is this the same or different than Xmlwriter?).

I'm still getting the same problem which is garbage DOCTYPE & markup
appended to the end of my XML document which keeps the browser from
launching

The browser is getting XML back from the server, but I'm still getting
the DOCTYPE appended. There output/error I'm getting from the browser
is:

<?mso-application progid="Word.Do cument"?>
<wsp:wordDocume nt xmlns:wsp="http ://schemas.microso ft.com/office/word/
2003/wordml/sp2"
.....{lengthy WordML content here}...
<w:r wsp:rsidR="0026 6357">
<w:tab wx:wTab="3300" wx:tlc="none

The XML page cannot be displayed Cannot view XML input using XSL
style sheet. Please correct the error and then click the Refresh
button, or try again later.

Cannot have a DOCTYPE declaration outside of a prolog. Error
processing resource 'http://localhost:3394/myPage.aspx?cn= Conf...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d"&...

=============== ===

My code is more or less:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Me.Load

Dim CNPath As String = "http://Localhost/myVirtualDirect ory/
myWordML.xml"
Dim XSLT_Path As String = "http://Localhost/myVirtualDirect ory/
myXSL.xslt"

' Load the style sheet.
Dim xslt As New XslCompiledTran sform(True) 'Enable XSLT
debugging
xslt.Load(XSLT_ Path)

' Create the writer.
Dim settings As New XmlWriterSettin gs()
settings.Indent = True
settings.Indent Chars = vbTab
settings.Confor manceLevel = ConformanceLeve l.Fragment

Response.ClearC ontent()
Response.Conten tType = "text/xml; charset=utf-8"

Dim writer As XmlWriter =
XmlWriter.Creat e(Response.Outp utStream, settings)

Dim reader As XmlReader = XmlReader.Creat e(CNPath)

reader.MoveToCo ntent()

xslt.Transform( reader, writer)

writer.Close()
reader.Close()
End Sub

=============== =======

The default page markup (which gives me the ""Validatio n (): Element
'html' occurs too few times" error mentioned above if I try to delete
it) suppied by VS2005 is:

<%@ Page Language="vb" AutoEventWireup ="false"
CodeBehind="CN_ XML.aspx.vb" Inherits="Digit alBuildBook.CN_ XML" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
</form>
</body>
</html>

May 17 '07 #5
Okay...I deleted the markup and found a post that explained how to
turn off the HTML validation error message:
Validation(): Element 'html' occurs too few times.
Turn off validations under : Tools -Options -Text Editor -HTML -Validation
I'm still not getting the browser to automatically launch the WordML
Add-In as I wanted, but I am getting well formed XML back from IIS so
I guess the answer to my original question was answered.

Thanks again everyone for your help.

-Paul

May 17 '07 #6
On May 17, 8:58 pm, linha...@aol.co m wrote:
>
I'm still not getting the browser to automatically launch the WordML
Add-In as I wanted, but I am getting well formed XML back from IIS so
Paul, try to set the Response.Conten tType in one of the following
values

"applicatio n/msword"
"applicatio n/msword-xml"
"applicatio n/vnd.ms-word.document.1 2"

and also check the following article

http://support.microsoft.com/kb/888579

Hope it helps

May 17 '07 #7
On May 17, 3:51 pm, hazyshadeofg... @hotmail.com wrote:
Just a suggestion...in your Page_Load event, try adding this at the
top:

Response.Conten tType = "text/xml; charset=utf-8";
XML files may open in Internet Explorer instead of opening in the
expected Office program when the ContentType header contains the
charset parameter
http://support.microsoft.com/kb/888579

May 17 '07 #8
On May 17, 1:57 pm, Alexey Smirnov <alexey.smir... @gmail.comwrote :
On May 17, 3:51 pm, hazyshadeofg... @hotmail.com wrote:
Just a suggestion...in your Page_Load event, try adding this at the
top:
Response.Conten tType = "text/xml; charset=utf-8";

XMLfiles may open in Internet Explorer instead of opening in the
expected Office program when the ContentType header contains the
charset parameterhttp://support.microso ft.com/kb/888579
Well, I'm getting close.

Response.Conten tType = "applicatio n/msword;charset= UTF-8"
Response.Conten tType = "applicatio n/msword"

Both cause IE to launch Winword.exe which pops up a "Convert File"
dialog box with a selection of Word formats (e.g. RTF, HTML, old
versions of word, wordperfect). If I select XML, a blank Word
application window pops up, but then the browser window takes focus
and the content is loaded in the browser window formatted like a word
document.

The charset setting doesn't seem to make a difference

The other two settings you suggested:
"applicatio n/msword-xml"
"applicatio n/vnd.ms-word.document.1 2"
just cause the XML to be sent directly to the browser and shown in
tree format.

The good news is that IE is definitely launching Word and is able to
display the content in Word format.

That bad news is:
(1) Word demands a convert to XML step on the client step.
(2) Word opens an unnecessary Word window before loading the content
into the browser window.
Both seem like solvable issues if I find the right settings.

Good tip on the charset issue. I saved the Output and then loaded it
in notepad and the header was:
<?xml version="1.0" encoding="UTF-8" standalone="yes "?>
<?mso-application progid="Word.Do cument"?>

I guess I'm overriding the charset setting somewhere else (maybe in my
XSLT transformation? ).

thanks again, you've been a big help,
-paul

May 18 '07 #9

<li******@aol.c omwrote in message
news:11******** **************@ o5g2000hsb.goog legroups.com...
On May 17, 1:57 pm, Alexey Smirnov <alexey.smir... @gmail.comwrote :
Both cause IE to launch Winword.exe which pops up a "Convert File"
dialog box with a selection of Word formats (e.g. RTF, HTML, old
versions of word, wordperfect). If I select XML, a blank Word
application window pops up, but then the browser window takes focus
and the content is loaded in the browser window formatted like a word
document.
The following code is working great for me without any prompt from Word
(2007). It means, that your output has any extra header that Word doesn't
like. Try to call Response.Clear( ) or Response.ClearH eaders() at the
beginning.

<script runat=server language="C#">
void Page_Load() {

Response.Clear( );
Response.Conten tType = "applicatio n/msword";

Response.Write( @"<?xml version=""1.0"" encoding=""UTF-8"" ?>
<?mso-application progid=""Word.D ocument""?>
<w:wordDocume nt
xmlns:w=""http://schemas.microso ft.com/office/word/2003/wordml"">
<w:body>
<w:p>
<w:r>
<w:t>My test document</w:t>
</w:r>
</w:p>
</w:body>
</w:wordDocument> ");
}
</script>
May 18 '07 #10

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

Similar topics

4
8131
by: Mark Wilson CPU | last post by:
This must be easy, but I'm missing something... I want to execute a Perl script, and capture ALL its output into a PHP variable. Here are my 2 files: ------------------------------------- test3.pl ------------------------------------- print "PERL Hello from Perl! (plain print)<br>\n"; print STDERR "PERL This is text sent to STDERR<br>\n"; $output="PERL Some output:<br>\n"; for ($i=0; $i<5; $i++) {
3
2780
by: edgekaos | last post by:
Is method 2 valid? Method 1: wstring input = L"STRING"; wstring output = input; transform(output.begin(), output.end(), output.begin(), towupper); Method 2: wstring input = L"STRING"; wstring output;
4
15066
by: Kevin Mansel via .NET 247 | last post by:
Ok, basically this is my problem. I'm building a console app tocall a dos program. So i'm using the Shell command to call theprogram, now depending on what happens, I want to read theoutput that this program returns. I'm just missing the stepshere. I know that I can set the Shell command to an integer,but this only returns a 0 to me telling me that it executed, notwhat is being returned to the console by that application. Isthere a way to...
24
2682
by: kalamantina | last post by:
#include "stdafx.h" #include <stdio.h> #define output( x ) printf( #x "\r\n" );fflush( stdout ) class CMyBase { public: CMyBase() { output( CMyBase() ); f(*this);
0
2061
by: newbie | last post by:
i'm a newbie of c language. can anyone help me to implement the code so that I can get the ciphertext from the output. thanks. #ifndef _3DES_H #define _3DES_H #ifndef uint8 #define uint8 unsigned char #endif
32
2772
by: spibou | last post by:
Is the output of the C preprocessor deterministic ? What I mean by that is , given 2 compilers which conform to the same standard, will their preprocessors produce identical output given as input the same file ? If not then how much variation is allowed ? Is it just a bit more or less white space here and there or could could there be larger differences ? If the output is not deterministic then is it possible that the output of the...
3
2618
by: MatsL | last post by:
Hi, This is seriously driving me crazy, could anyone explain to me why neither of these doesn't produce XHTML compliant output (it is being called in Render() btw): output.WriteLine("<img src=\"" + vars + " />"); output.AddAttribute(HtmlTextWriterAttribute.Src, (string)vars); output.RenderBeginTag(HtmlTextWriterTag.Img);
3
4654
by: undshan | last post by:
I am writing a code that needs to open a file, create an output file, run through my function, prints the results to the output file, and closes them within a loop. Here is my code: #include <stdlib.h> #include <stdio.h> #include <math.h> #include <string.h> #include "util.h" //Main Loop
5
3320
by: amit.uttam | last post by:
Hey everyone, I've recently jumped big time into python and I'm working on a software program for testing automation. I had a question about proper logging of output. What I would like is: 1. a function syslog (to log output to log file only) 2. a function stdout (to log output to stdout only) 3. a function sslog (to log output to both log and stdout)
2
3370
by: gabosom | last post by:
Hi! I've been breaking my head trying to get the output variables from my Stored Procedure. This is my SP code CREATE PROCEDURE GetKitchenOrderDetail( @idService int, --outPut Variables @idUser int OUTPUT,
0
8372
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8285
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8814
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8475
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8591
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7304
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5621
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4293
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2709
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.