473,396 Members | 1,933 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,396 software developers and data experts.

Return XML. Please, need help. Thanks.

Hello,

For the past hours I have been trying to solve a problem which is
driving me crazy.

I have to different codes where the problem to solve is the same:

CODE 1 (Transforms a XML document using a XSL file):

Function Trans()
Dim doc As XmlDocument = New XmlDocument
doc.Load("doc.xml")
Dim docXsl As XslCompiledTransform = New XslCompiledTransform
docXsl.Load("doc.xsl")
docXsl.Transform(doc, Nothing,
HttpContext.Current.Response.Output)
End Function
CODE 2 (Creates XML)

Function Create()
Dim doc As XmlTextWriter = New
XmlTextWriter(Response.OutputStream, Encoding.UTF8)
...
doc.WriteStartElement("item")
doc.WriteElementString("title", "My Title")
doc.WriteEndElement()
...
doc.Flush()
doc.Close()
End Function
I don't want to display the XML files. I don't want to save the XML
files.

I want to return the XML created from each function.
Then outside of each function I want to display the XML in the browser.

Yes, I read about stream or using a string.
But I was not able to make this work.

Could someone please help me out?
Please, give me a code example.

Thank You Very Much,
Miguel

Oct 31 '06 #1
1 1682
You're currently writing the transformed Xml to the Response stream.
The easiest change to your code is (forgive VB.Net typos, I'm a C# guy)

Function Trans() As Stream
Dim outputStream As Stream = New MemoryStream
Dim doc As XmlDocument = New XmlDocument
Dim docXsl As XslCompiledTransform = New XslCompiledTransform

' Grab and transform the data into the stream
doc.Load("doc.xml")
docXsl.Load("doc.xsl")
docXsl.Transform(doc, Nothing, outputStream)

'Set the stream back to the beginning
outputStream.Seek(0,0)
Return outputStream
End Function

And now you're returning a MemoryStream containing your transformed
xml. You can read the data with an XmlReader, flush it to a file or
database, or write it directly to your HttpResponse.

shapper wrote:
Hello,

For the past hours I have been trying to solve a problem which is
driving me crazy.

I have to different codes where the problem to solve is the same:

CODE 1 (Transforms a XML document using a XSL file):

Function Trans()
Dim doc As XmlDocument = New XmlDocument
doc.Load("doc.xml")
Dim docXsl As XslCompiledTransform = New XslCompiledTransform
docXsl.Load("doc.xsl")
docXsl.Transform(doc, Nothing,
HttpContext.Current.Response.Output)
End Function
CODE 2 (Creates XML)

Function Create()
Dim doc As XmlTextWriter = New
XmlTextWriter(Response.OutputStream, Encoding.UTF8)
...
doc.WriteStartElement("item")
doc.WriteElementString("title", "My Title")
doc.WriteEndElement()
...
doc.Flush()
doc.Close()
End Function
I don't want to display the XML files. I don't want to save the XML
files.

I want to return the XML created from each function.
Then outside of each function I want to display the XML in the browser.

Yes, I read about stream or using a string.
But I was not able to make this work.

Could someone please help me out?
Please, give me a code example.

Thank You Very Much,
Miguel
Oct 31 '06 #2

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

Similar topics

3
by: fig000 | last post by:
Hi, I'm relatively new to Javascript so please bear with me on what might sound like silly questions. This is what I want to do: I'm working in classic asp (I have to for this project). I...
4
by: Garibaldi | last post by:
Folks, I'm having a bad regex day and can sure use your help, please.. I have a Regex expression that works fine. It's purpose is to isolate all data from the start of a string begining with...
1
by: Jack Addington | last post by:
I have a 3rd party object that fires an itemchanged event when someone edits some data on a form. This event has a custom eventArgs that has a field called ActionCode. In the code of the event,...
6
by: Sunny | last post by:
Hi, I have a very serious issue at hand. I have created a small C# Console App (Csd.exe) that collects a list of files as its argument and generates their Md5 sets. This application is used by...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
9
by: MSDNAndi | last post by:
Hi, I have a set of simple webservices calls that worked fine using .NET Framework 1.0. I am calling a Java/Apache based webservices, the calling side is not able to supply a proper WSDL. ...
18
by: Axel Dahmen | last post by:
Hi, trying to submit an ASPX form using the key (using IE6) the page is not submitted in my web project. Trying to debug the pages' JavaScript code I noticed that there's some ASP.NET client...
2
by: jennk | last post by:
i am working in Access 97, our database tables are linked from ODBCsqlsvr (not even sure what that means). i have a table where each record has a unique customer and their order information. there...
6
by: SethM | last post by:
I have a stored procedure that returns a record set. I want to functionalize this so I can have multiple presentations of the same record set. However, I can not get rs_event.open StoreProc to pass...
5
by: TompIfe | last post by:
Hi, I have a web service that reads data from an Access database using datareader and place the data in an array that the web method returns. Now, I want to make the web service also to return an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...

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.