473,511 Members | 15,178 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Including XmlDocument fragments in an XmlTextWriter

My program is constructing a document from several fragments, which are
created on the fly using XSL transformations. I've managed to store the
output from each transformation (each fragment) in an XmlDocument
object, and I can include that in the collected document using code like
this:

w.WriteRaw(xmlDoc.DocumentElement.InnerXml)

The problem is that when I use WriteRaw(), there's no awareness of which
namespaces are already in scope at the point where the fragment is
included. The included fragments all belong to a namespace which is
declared in the root element of the result document.

I can imagine solving this by traversing the XmlDocument node by node
and adding elements using WriteStartElement(), WriteAttributeString()
and so on, but it seem like a lot of work. Is there an easier way to do
it? Perhaps storing the output from transformations as XmlDocument is
wrong in the first place? Any help on this would be much appreciated.

Gustaf
Jun 18 '06 #1
2 1540
Gustaf wrote:
My program is constructing a document from several fragments, which are
created on the fly using XSL transformations. I've managed to store the
output from each transformation (each fragment) in an XmlDocument
object, and I can include that in the collected document using code like
this:

w.WriteRaw(xmlDoc.DocumentElement.InnerXml)

The problem is that when I use WriteRaw(), there's no awareness of which
namespaces are already in scope at the point where the fragment is
included. The included fragments all belong to a namespace which is
declared in the root element of the result document.

I can imagine solving this by traversing the XmlDocument node by node
and adding elements using WriteStartElement(), WriteAttributeString()
and so on, but it seem like a lot of work. Is there an easier way to do
it? Perhaps storing the output from transformations as XmlDocument is
wrong in the first place? Any help on this would be much appreciated.


xmlDoc.DocumentElement.WriteTo(w);

--
Oleg Tkachenko [XML MVP, MCAD]
http://www.XmlLab.Net | http://www.XLinq.Net | http://blog.tkachenko.com
Jun 18 '06 #2
Oleg Tkachenko [MVP] wrote:
xmlDoc.DocumentElement.WriteTo(w);


Wow! One line code of changed, and it's all working! Thank you very much!

Gustaf
Jun 18 '06 #3

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

Similar topics

1
1288
by: Tarren | last post by:
Hi: I want to append a new transaction to a transaction log. The transaction log is trans.xml <transactions> <transaction> <id>12</id> <stamp>1/1/1900 12:02</stamp>
3
9028
by: Dan | last post by:
Is there a better way to include the XML declaration than the following? XmlDeclaration dec =m_XMLDocument.CreateXmlDeclaration("1.0",string.Empty, "yes");...
4
14762
by: barney | last post by:
Hello, I' m using .NET System.Xml.XmlDOcument. When I do the following: XmlDocument xml = new XmlDocument(); xml.Load("blah"); .... xml.Save("blub"); I've got the problem that the following...
3
10956
by: TnaG | last post by:
Can someone answer this probably obvious question. I have an xmldocument that i want to apply an xslt file to. All the examples i find assume u are applying the xslt to an xml file you've read...
3
15777
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...
5
2505
by: Andy Fish | last post by:
Hi, I am using XmlDocument.WriteTo() and I find that the xml declaration is not included. at the moment I am doing this: XmlTextWriter xw = new XmlTextWriter(...); xw.WriteStartDocument();...
0
1019
by: Baren | last post by:
Hi! All, I am facing a problem while creating a XMLDocument from a XmlSerialized Object . Here is my code and the error I am getting. Can anyone help me out. Check the attribute value of EmpID...
2
2351
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...
4
3260
by: =?Utf-8?B?TWFyaw==?= | last post by:
Hi... We've got a lot of places in our code where we read relatively small xml user preference blocks. Currently that's creating a new XmlDocument in every spot. I was thinking we might see...
0
7237
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
7137
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
7417
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
7506
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...
1
5063
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...
0
4734
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...
0
3219
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...
0
3210
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1572
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 ...

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.