Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / October 2007

Tip: Looking for answers? Try searching our database.

XmlTextWriter, XmlDocument

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ars Comm - Ciro Ferraiuolo - 17 Oct 2007 15:16 GMT
Hi all, I need to embed an image to an existing xml file. I guess this is
possible using XmlTextWriter.WriteBase64() method. My problem is that
XmlTextWriter writes to a new document.
How can I edit an existing doc (for example with XmlDocument class) and
write an image to it?
I'm sorry but I'm a bit confused about the difference between XmlTextWriter
and XmlTextDocument.

Thanks.
Vadym Stetsiak - 17 Oct 2007 15:36 GMT
Hello, Ars!

To put it simple with XmlDocument you're working with object model of the
XML file, XmlTextWriter is doesn't introduce object model.
Working with XmlTextWriter puts more work on you as a developer.

IMO with XmlDocument it is far more simple to edit xml documnet.

With XmlDocument getting to the necessary node will look like:

XmlDocument xmlDoc= new XmlDocument();
xmlDoc.Load(xmlFile);
XmlNode toWrite = xmlDoc.SelectSingleNode(xpathToNode);

now you can create attributes or create text section.
and then save the document
xmlDoc.Save(file);

Since XmlDocument builds in-memory object model of the XML file it consumes
more memory then XmlTextWriter.
If you have small xmldocument it is not an issue.

--
With best regards, Vadym Stetsiak.
Blog: http://vadmyst.blogspot.com

You wrote  on Wed, 17 Oct 2007 16:16:35 +0200:

ACC> Hi all, I need to embed an image to an existing xml file. I guess
ACC> this is  possible using XmlTextWriter.WriteBase64() method. My
ACC> problem is that
ACC> XmlTextWriter writes to a new document.
ACC> How can I edit an existing doc (for example with XmlDocument class)
ACC> and  write an image to it?
ACC> I'm sorry but I'm a bit confused about the difference between
ACC> XmlTextWriter  and XmlTextDocument.

ACC> Thanks.
Ciri - 17 Oct 2007 15:57 GMT
Ok, perfect. Let's say I use the
xmlDoc.AppendChild(xmlDoc.CreateElement(....))...How to put the image in?

> Hello, Ars!
>
[quoted text clipped - 34 lines]
>
> ACC> Thanks.
Vadym Stetsiak - 17 Oct 2007 16:15 GMT
Hello, Ciri!

Using Base64 format you can add that image as a text section to newly
created XmlElement object.

say,
byte[] image;
XmlElement xmlImage = xmlDoc.CreateElement("image");

XmlText imageText = xmlDoc.CreateText(Convert.ToBase64String(image));
xmlImage.AppendChild(imageText);

xmlDoc.AppendChild(xmlImage);

Note, that Convert class also has a method to get back byte array
Convert.FromBase64String(...);
--
With best regards, Vadym Stetsiak.
Blog: http://vadmyst.blogspot.com

You wrote  on Wed, 17 Oct 2007 16:57:47 +0200:

C> Ok, perfect. Let's say I use the
C> xmlDoc.AppendChild(xmlDoc.CreateElement(....))...How to put the image
C> in?

C> "Vadym Stetsiak" <vadmyst@gmail.com> ha scritto nel messaggio
C> news:eDKnnqMEIHA.5324@TK2MSFTNGP02.phx.gbl...
>> Hello, Ars!

>> To put it simple with XmlDocument you're working with object model of
>> the
>> XML file, XmlTextWriter is doesn't introduce object model.
>> Working with XmlTextWriter puts more work on you as a developer.

>> IMO with XmlDocument it is far more simple to edit xml documnet.

>> With XmlDocument getting to the necessary node will look like:

>> XmlDocument xmlDoc= new XmlDocument();
>> xmlDoc.Load(xmlFile);
>> XmlNode toWrite = xmlDoc.SelectSingleNode(xpathToNode);

>> now you can create attributes or create text section.
>> and then save the document xmlDoc.Save(file);

>> Since XmlDocument builds in-memory object model of the XML file it
>> consumes more memory then XmlTextWriter.
>> If you have small xmldocument it is not an issue.

>> --
>> With best regards, Vadym Stetsiak.
>> Blog: http://vadmyst.blogspot.com

>> You wrote  on Wed, 17 Oct 2007 16:16:35 +0200:

ACC>>> Hi all, I need to embed an image to an existing xml file. I guess
ACC>>> this is  possible using XmlTextWriter.WriteBase64() method. My
ACC>>> problem is that
ACC>>> XmlTextWriter writes to a new document.
ACC>>> How can I edit an existing doc (for example with XmlDocument
ACC>>> class)
ACC>>> and  write an image to it?
ACC>>> I'm sorry but I'm a bit confused about the difference between
ACC>>> XmlTextWriter  and XmlTextDocument.

ACC>>> Thanks.
Ciri - 17 Oct 2007 16:18 GMT
Wow! That's it.
Thank you very much.

> Hello, Ciri!
>
[quoted text clipped - 63 lines]
>
> ACC>>> Thanks.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.