473,698 Members | 2,571 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XmlTextWriter to XmlDocument in .net framework 2.0

Is there a way I can write to an XmlDocument using an XmlWriter style
interface efficiently in the framework 2.0?

In 1.1, you could write to a MemoryStream then load that into an
XmlDocument, but this was pretty inefficient. The XmlNodeWriter sample
helped here and I was expecting that to appear in the 2.0 framework but
it doesn't appear to be there.

Am I missing something?

Dec 10 '06 #1
1 5947
James Berry wrote:
Is there a way I can write to an XmlDocument using an XmlWriter style
interface efficiently in the framework 2.0?

In 1.1, you could write to a MemoryStream then load that into an
XmlDocument, but this was pretty inefficient. The XmlNodeWriter sample
helped here and I was expecting that to appear in the 2.0 framework but
it doesn't appear to be there.

Am I missing something?
XPathNavigator over an XmlDocument/XmlNode is editable in .NET 2.0 and
provides ways to feed XmlWriter output into the document/node e.g. this

XmlDocument xmlDocument = new XmlDocument();
using (XmlWriter xmlWriter =
xmlDocument.Cre ateNavigator(). AppendChild()) {
xmlWriter.Write StartDocument() ;
xmlWriter.Write StartElement("g ods");
xmlWriter.Write ElementString(" god", "Kibo");
xmlWriter.Write EndDocument();
}
xmlDocument.Sav e(Console.Out);

outputs

<gods>
<god>Kibo</god>
</gods>
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Dec 10 '06 #2

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

Similar topics

5
6156
by: reddy | last post by:
I am trying to insert a node into an XMLFile. using XMLTextwriter. My Question is Is it possible to do without using XMLDocument. Because its loading all the the file into memory. I just want to insert in the front. My code is give below. Is it possible to do without using XMLDOcument? Dim masterDoc As String = Request.PhysicalApplicationPath & "PageViews.xml" Dim writer As XmlTextWriter = Nothing
4
11524
by: H Lee | last post by:
Hi, I'm an XML newbie, and not sure if this is the appropriate newsgroup to post my question, so feel free to suggest other newgroups where I should post this message if this is the case. I'm having issues using XmlTextWriter, saving it out to a file with UTF8 encoding, and seeing "dirty", or "human unreadable" characters show up *right before* the XML declaration. I need to have the XML declaration state "encoding = utf-8", but also...
3
15800
by: Gustaf Liljegren | last post by:
I think I must use MemoryStream, but whenever I search for examples of MemoryStream, I get lots byte-per-byte reading, buffers and so on. It's hard to understand and seem overkill for my case anyway. All I want is moving a finished document from XmlTextWriter into an XmlDocument. Can anyone give a short example? Gustaf
8
2488
by: Charles.Deisler | last post by:
Im currently using the following code.. XmlDocument xmlData = new XmlDocument(); XmlTextWriter xmlwriter = new XmlTextWriter(Response.OutputStream,System.Text.Encoding.UTF8); XmlReader xmlreader = SqlHelper.ExecuteXmlReader(...) xmlData.Load(xmlreader); xmlData.WriteTo(xmlwriter); xmlwriter.Flush();
1
2416
by: st | last post by:
Hi, I've a routine that exports a DB query to Excel by building an XmlDocument and saving to a XmlTextWriter. I'm having trouble with carriage returns in a mailing address not showing up in the final Excel sheet. What's added to the InnerText of an XmlDocument is something similar to:
0
1096
by: Martin | last post by:
Hi, I am retriving data from sql server using the xml raw clause and an xmltextwriter. this is working out fine except the xml raw clause does not put a root node on the xml that is returned from sql server and subsequently an xmldocument can't be created from the xmltextwriter as there is no root element. however if the xml raw query returns only a single row then there is a root
0
1287
by: Martin | last post by:
Hi, I am retriving data from sql server using the xml raw clause and an xmltextwriter. this is working out fine except the xml raw clause does not put a root node on the xml that is returned from sql server and subsequently an xmldocument can't be created from the xmltextwriter as there is no root element. however if the xml raw query returns only a single row then there is a root
4
3115
by: quest | last post by:
Is there anyway I can generate the xml in the following format using XmlTextWriter ? Intended output: <?xml version="1.0" ?> I tried: XmlTextWriter xmlWriter = new XmlTextWriter(xmlFileName, null); xmlWriter.Namespaces = false;
2
2361
by: ajc308 | last post by:
My current code contains a hardcoded filename for the XmlTextWriter to write to, and then an XmlDocument loads that file. I am looking to replace the hardcoded filename with something, anything that will retain the contents that the XmlTextWriter outputs. My code: XslCompiledTransform myXslTrans = new XslCompiledTransform(); myXslTrans.Load("sortByExtension.xsl"); XmlTextWriter XmlWrite = new XmlTextWriter("results.xml", null);...
0
8610
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
9031
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8873
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...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4623
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
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
2
2339
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.