473,396 Members | 1,847 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.

XML Document. How can I do this?

Hello,

I am creating an IHttp Handler that sends an XML file as response.

The XML file is created at runtime. I think the correct way is to save
it to a stream.

I have:

1 XDocument sitemap = new XDocument();
2 // Fill XDocument
3 Stream stream = new MemoryStream();
4 sitemap.Save(stream);
5 context.Response.Clear();
6 context.Response.ContentType = "text/xml; charset=utf-8";
7 context.Response.Write(stream);
8 context.Response.End();

But I am getting the following errors:

The best overloaded method match for
'System.Xml.Linq.XDocument.Save(System.Xml.XmlWrit er)' has some
invalid arguments
Argument '1': cannot convert from 'System.IO.Stream' to
'System.Xml.XmlWriter'

I am trying to use XDocument to be able to use code that I already
created on my project where I use Linq:

XElement gallery = file.Document.Elements("gallery").FirstOrDefault() ;

XElement album = (from a in gallery.Elements("album")
where (Guid?)a.Attribute("id") == id
select a).FirstOrDefault();

album.Add(new XElement("img",
new XAttribute("id", paper.Slide.SlideID),
new XAttribute("caption", paper.Slide.Caption ?? ""),
new XAttribute("src", Path.GetFileName(paper.Slide.Path ?? "")),
));

How can I solve this?

Thanks,

Miguel
Oct 1 '08 #1
1 2022
First - note that you can probably write directly to the response:

sitemap.Save(context.Response.Output);

For completeness - to write to a /stream/, you would wrap with an
XmlWriter:

// (note optional options overload for more control)
using (XmlWriter writer = XmlWriter.Create(stream))
{
sitemap.Save(writer);
writer.Close();
}

Again, ideally you might write directly to the underlying stream -
context.Response.OutputStream;

Marc
Oct 2 '08 #2

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

Similar topics

1
by: techy techno | last post by:
Hii Just wanted to know how can I decorate my texboxes and Listmenu which is called from a JS file using the following code below: document.write("<SELECT NAME='cur2' ONCHANGE='cconv1();'>");...
3
by: Rosinger | last post by:
Hi all, What is the preferred in term of browser copatability to get a reference to an element in the document in JavaScript? I am not sure about when to use document.all or document.layers or...
1
by: chirs | last post by:
Hi, Is there a difference between document.tagID and document.all.tagID. I've seen both like: document.myImage1.src = "nextImage2.jpg" and document.all.hot1.style.color= ... where hot1 is in...
3
by: Gary Mayor | last post by:
Hi, I'm re phrasing and earlier question as the earlier question doesn't make to much sense. I using document.onmousemove to move a <div line on the screen. At the moment if I click and move the...
10
by: InvisibleMan | last post by:
Hi, Thanks for any help in advance... Okay, I have the JS listed below that calls for the display of the (DIV) tag... cookie function not included, as don't feel its necessary but you'll get the...
9
by: alu | last post by:
Could someone explain the discrepancies within and between the stated definitions / usage of 'document.location' , 'document.URL' vs. their actual functionality? Should they be read-only when in...
2
by: Gulliver | last post by:
Gurus please help! Using VB.net I would like to do the following: 1. Open up a doc or rtf file in my application 2. Search through the text using keywords 3. Select portions of the text by...
13
by: RommelTJ | last post by:
Hi, My website (http://www.justiceinmexico.org/indextest.php) looks good in Firefox, but horrible in IE, and I think it's because of an error in the javascript of a free web ticker I got off the...
8
by: Mateusz Viste | last post by:
Hi, I am trying make some multimedia files playable from my website. So far, I am able to generate dynamically a new page containing the right <embed> section. However, when I load my script, it...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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...

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.