XmlTextWriter Usage question

I would like to store the contents of the xml created via the XmlTextWriter 
to a string as opposed to a file.   Is this possible ? If so how ?  Is this 
the best way to create xml that gets stored to a variable?  Am I better off 
using the xmldom ? 


0
robc11 (5)
11/8/2006 2:57:03 AM
dotnet.xml 7266 articles. 0 followers. Follow

5 Replies
773 Views

Similar Articles

[PageSpeed] 26

This is possible, in fact it's even pretty easy.

Create a StringWriter that writes to a stringbuilder, or a stream based on a 
memory stream. Pass either of these to the XmlTextWriter, perform your 
operations, then pull your string out of the stringbuilder or the memory 
stream.

It's about 3 lines of code, total...

--
Chris Mullins, MCSD.Net, MCPD:Enterprise
http://www.coversant.net/blogs/cmullins


"Rob" <robc1@yahoo.com> wrote in message 
news:y8adnWWB1Mae28zYnZ2dnUVZ_rudnZ2d@comcast.com...
>I would like to store the contents of the xml created via the XmlTextWriter 
>to a string as opposed to a file.   Is this possible ? If so how ?  Is this 
>the best way to create xml that gets stored to a variable?  Am I better off 
>using the xmldom ?
> 


0
cmullins (4)
11/8/2006 3:39:57 AM
Chris,

Would it work something like...

Dim sb as New StringBuilder
Dim sw as New StringWriter(sb)
Dim tw as New XmlTextWriter(sw)

With tw
 .Indentation = 4
  ' code to build xml. ...
 .WriteEndDocumnet()
End with

tw.Flush()
tw.Close()

But now how do I view the contents of  tw

MsgBox(tw) does not work
Textbox1.Text = tw does not work

Thanks,
Rob


"Chris Mullins" <cmullins@yahoo.com> wrote in message 
news:%23OjWReuAHHA.4256@TK2MSFTNGP04.phx.gbl...
> This is possible, in fact it's even pretty easy.
>
> Create a StringWriter that writes to a stringbuilder, or a stream based on 
> a memory stream. Pass either of these to the XmlTextWriter, perform your 
> operations, then pull your string out of the stringbuilder or the memory 
> stream.
>
> It's about 3 lines of code, total...
>
> --
> Chris Mullins, MCSD.Net, MCPD:Enterprise
> http://www.coversant.net/blogs/cmullins
>
>
> "Rob" <robc1@yahoo.com> wrote in message 
> news:y8adnWWB1Mae28zYnZ2dnUVZ_rudnZ2d@comcast.com...
>>I would like to store the contents of the xml created via the 
>>XmlTextWriter to a string as opposed to a file.   Is this possible ? If so 
>>how ?  Is this the best way to create xml that gets stored to a variable? 
>>Am I better off using the xmldom ?
>>
>
> 


0
robc11 (5)
11/8/2006 4:39:33 AM
Rob wrote:
> Would it work something like...
> 
> Dim sb as New StringBuilder
> Dim sw as New StringWriter(sb)
> Dim tw as New XmlTextWriter(sw)
> 
> With tw
>  .Indentation = 4
>   ' code to build xml. ...
>  .WriteEndDocumnet()
> End with
> 
> tw.Flush()
> tw.Close()
> 
> But now how do I view the contents of  tw
> 
> MsgBox(tw) does not work
> Textbox1.Text = tw does not work

Even simpler

Dim sw as New StringWriter()
Dim tw as New XmlTextWriter(sw)

With tw
  .Indentation = 4
   ' code to build xml. ...
  .WriteEndDocumnet()
End with

tw.Close()

MsgBox(sw.ToString())

-- 
Oleg Tkachenko [XML MVP, MCPD]
http://blog.tkachenko.com | http://www.XmlLab.Net | http://www.XLinq.Net
0
some2113 (163)
11/8/2006 8:52:00 AM
Thanks very much !

"Oleg Tkachenko [MVP]" <some@body.com> wrote in message 
news:45519AB0.1030609@body.com...
> Rob wrote:
>> Would it work something like...
>>
>> Dim sb as New StringBuilder
>> Dim sw as New StringWriter(sb)
>> Dim tw as New XmlTextWriter(sw)
>>
>> With tw
>>  .Indentation = 4
>>   ' code to build xml. ...
>>  .WriteEndDocumnet()
>> End with
>>
>> tw.Flush()
>> tw.Close()
>>
>> But now how do I view the contents of  tw
>>
>> MsgBox(tw) does not work
>> Textbox1.Text = tw does not work
>
> Even simpler
>
> Dim sw as New StringWriter()
> Dim tw as New XmlTextWriter(sw)
>
> With tw
>  .Indentation = 4
>   ' code to build xml. ...
>  .WriteEndDocumnet()
> End with
>
> tw.Close()
>
> MsgBox(sw.ToString())
>
> -- 
> Oleg Tkachenko [XML MVP, MCPD]
> http://blog.tkachenko.com | http://www.XmlLab.Net | http://www.XLinq.Net 


0
robc11 (5)
11/8/2006 1:00:00 PM
Just change:
> MsgBox(tw)

to:
MsgBox(sb.ToString())

--
Chris Mullins, MCSD.NET, MCPD:Enterprise
http://www.coversant.net/blogs/cmullins

"Rob" <robc1@yahoo.com> wrote in message 
news:frudnZVIB9eWw8zYnZ2dnUVZ_qudnZ2d@comcast.com...
> Chris,
>
> Would it work something like...
>
> Dim sb as New StringBuilder
> Dim sw as New StringWriter(sb)
> Dim tw as New XmlTextWriter(sw)
>
> With tw
> .Indentation = 4
>  ' code to build xml. ...
> .WriteEndDocumnet()
> End with
>
> tw.Flush()
> tw.Close()
>
> But now how do I view the contents of  tw
>
> MsgBox(tw) does not work
> Textbox1.Text = tw does not work
>
> Thanks,
> Rob
>
>
> "Chris Mullins" <cmullins@yahoo.com> wrote in message 
> news:%23OjWReuAHHA.4256@TK2MSFTNGP04.phx.gbl...
>> This is possible, in fact it's even pretty easy.
>>
>> Create a StringWriter that writes to a stringbuilder, or a stream based 
>> on a memory stream. Pass either of these to the XmlTextWriter, perform 
>> your operations, then pull your string out of the stringbuilder or the 
>> memory stream.
>>
>> It's about 3 lines of code, total...
>>
>> --
>> Chris Mullins, MCSD.Net, MCPD:Enterprise
>> http://www.coversant.net/blogs/cmullins
>>
>>
>> "Rob" <robc1@yahoo.com> wrote in message 
>> news:y8adnWWB1Mae28zYnZ2dnUVZ_rudnZ2d@comcast.com...
>>>I would like to store the contents of the xml created via the 
>>>XmlTextWriter to a string as opposed to a file.   Is this possible ? If 
>>>so how ?  Is this the best way to create xml that gets stored to a 
>>>variable? Am I better off using the xmldom ?
>>>
>>
>>
>
> 


0
cmullins (4)
11/9/2006 6:46:21 PM
Reply:

Similar Artilces:

SFO question/help/advice?
I have a laptop that is connected to domain "A". The user logs into this domain, collects email etc.. CRM is on a SBS 2003 box on its own domain "B" The user can access CRM - using pass through authentication. I have loaded SFO on to the laptop, I can see CRM online and SYNC to go offline does not give me an error. However, when offline I get the standard "access denied" error. I'm assuming that this is because it because I'm not logged into the same domain as CRM - and the synced user data is for B\mike and I am logged in as A\mike. Does anyon...

Protection question
hi how i can protect the unlocked cells against replacing each other(whe holding mouse cleck and move a cell to another)?? thanx in advanc -- Message posted from http://www.ExcelForum.com Hi you can't (at least not without VBA / event code) -- Regards Frank Kabel Frankfurt, Germany "autocad >" <<autocad.1bnqfc@excelforum-nospam.com> schrieb im Newsbeitrag news:autocad.1bnqfc@excelforum-nospam.com... > hi > > how i can protect the unlocked cells against replacing each other(when > holding mouse cleck and move a cell to another)?? > > thanx in ...

FRx Tree Question
Hi, This is a part of my tree: SUMMARY^R^21 SUMMARY^R^21^150 SUMMARY^R^21^160 SUMMARY^R^21^170 SUMMARY^R^25 SUMMARY^R^25^150 SUMMARY^R^25^160 SUMMARY^R^25^170 I have the following formula: Description: 5610 Some Revenue, Fmt Code: CAL, Related Rows/Unit: IF @UNIT(SUMMARY^R^21) THEN @691*3 This will give me an amount for SUMMARY^R^21 only. I want an amount to appear for SUMMARY^R^21^150, SUMMARY^R^21^160, and SUMMARY^R^21^170. In order to do this I have to add 3 more formulas(e.g.IF @UNIT(SUMMARY^R^21^150) THEN @691*3). The thing is that my tree is big and i will need about 150 formulas t...

A Few Questions
1) Is there a way to print out a profit margin report ONLY for items that have been "last received" on any given day. I would like to change my pricing based upun cost and be able to check that for items that I have received that day. 2) My store has over 9000 sku's...is there a way to set up the system so that items cannot ring out for less than cost? For new items I am entering "lower bound pricing", but for the thousands of old items....is there a way to set it up automatically for all of them without going to each individual item and entering the cost? T...

Newbie Time Question #2
Great Info. Thank you very much. Any books you could recommend that would help me in understanding creating formulas like this? I would like to get more out of excel this is great stuff. Most of the books I see are a general overview o the application.... Unless I looking at the wrong stuff -- ACangem ----------------------------------------------------------------------- ACangemi's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=858 View this thread: http://www.excelforum.com/showthread.php?threadid=26314 There are a few books on Excel formulas listed here...

Dumb Exchange OWA Question
I have a single Exchange 2003 with SP1 server running on W2K3 server. I can access OWA fine by going to http://exchange/exchange. However if I try http://exchange.mydomainname.com/exchange or even http://(The IP ADDRESS)/exchnage, I get page "The page cannot be found". What have I over looked? Are you testing this internally or externally? If its external, make you have a hole in the firewall to the appropriate server. "Wayne" <Wayne@discussions.microsoft.com> wrote in message news:A4573A1E-50EE-4A3D-9D34-2644EB20A246@microsoft.com... >I have a single ...

XmlTextWriter and whitespace
Hi, I've a routine that exports a DB query to Excel by building an XmlDocument and saving to a XmlTextWriter. The function works but new lines don't show up, i.e. significant whitespace is cut. I've tried adding WriteAttributeString("xml", "space", null, "preserve") to the XmlTextWriter just prior to save, but that results in the error: "Index was outside the bounds of the array." Can anyone assist? Many thanks, Simon Lane Have you tried playing with the PreserveWhitespace property of XmlDocument? <st@jpa.co.jp> wrote in message...

PDF question
Our (non-profit) organization puts out a newsletter (created in Publisher), and we'd like to convert it to PDF to send it to some people that way. I know how to do this (I have Primo PDF), but when I just did it, the fonts in (small) sections on two of the pages were garbled. In one instance it was an unusual font, so I thought that might be the problem. But in the other instance it's not an unusual font. Is there any way I can change/correct the garbled font? I have Adobe Acrobat reader 5.0. Seems like I might have tried to upgrade a while back and it didn't "ta...

Chart Question #5
I have 5 points (labeled 1 thru 5) that are randomly generated each with an x,y coordinates. I want to plot them on a scatter diagram and then ID each point by its label not its coordinates. Can somebody help. Hi, Download the free add in at http://www.appspro.com/Utilities/ChartLabeler.htm this is designed just for this purpose. -- Thanks, Shane Devenshire "Xl2007" wrote: > I have 5 points (labeled 1 thru 5) that are randomly generated each with an > x,y coordinates. I want to plot them on a scatter diagram and then ID each > point by its label not its coordinat...

Autocomplete email address question..
When I type the letters of a name in the To: box, autocomplete suggests a list of names from which I may choose. Here is my problem - I have about 8 groups under my contacts and somehow it is only set to look for the matching names in one of the groups. but I want to add one more group to this - how do I do it?? Thanks! Terri <phiter@mail.com> wrote: > When I type the letters of a name in the To: box, autocomplete > suggests a list of names from which I may choose. Here is my problem > - I have about 8 groups under my contacts and somehow it is only set > to look fo...

how do I import a XMLTextWriter into an XMLDOCUMENT?
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> </transaction> </transactions> Basically I have been able to make the new TRANSACTION fragments using an XMLTextWriter. My XMLDocument loads the xml file from disk. How do I 'import' or 'insert' the contents of the XMLTextWriter into my XMLDocument. All of the examples I have seen write straight to the file, but replace whatever was al...

lookup question #3
How do you do a lookup within a lookup? Say I have a list of game results, Home Team Name in cell A800, Road Team Name in B800, score in C800, date in K800. I want to return the home team's rating on that date. The rating comes from a series of team logs within in the same sheet. For example, Everton's name would be in A2, Blackburn's in A42, etc. Starting in A6 (Blackburn's in A46, etc) would be Everton's own log of games, (again, Home Team Name in column A6:A30, Road Team Name in column B, Date in column K), but with a rating in column R. So I have to first read cel...

Question on CRM Workplace Usage
Just a usage question... Incoming CRM emails show up in workplace under the E-Mail folder and as an activity How do people manage emails here in the CRM workplace area? If you're not assigning it to anybody, I don't see anyway of putting it in another folder. All I see that you can do is delete it and I don't want to do that. Am I missing something here? I can see now that if you choose to be a "Service User" instead of a "Sales User", you can accept emails. What do you do with them after that though? Do they just sit in the In Progress folder ...

CRM and Fax automation question
Hi, I'm looking for a good or better fax server that can be easily and seamlessly integrate with MS CRM 3.0 or 4.0. I'm thinking of RightFAX or GFIFax... or even if I install these fax server in my environment, do I still need to do programming and customizations, such as post callout when a new Fax activity is created? Please advise :) You immediate response is appreciated. "Benjamin Fallar III" <fallar@pldtdsl.net> wrote in message news:3484C69D-B193-4B48-86A4-A4529D9DE4C6@microsoft.com... > I'm thinking of RightFAX or GFIFax... or even if I install ...

Bookmark in Hyperlink Question
I have an excel file located in the "O" drive that has a hyperlink pointed with specific bookmarks (O:\Book1.xls-Sheet2!A1) However, when I save as this excel file into the “C” drive the new file keeps the hyperlink and bookmarks from the “O”. If there is many way to save as the excel file from the “O” drive into the “C” and the hyperlink with its respectively bookmark into the “C” drive (C:\Book1.xls-sheet2!A1). Thanks in advance. Maperalia I didn't check this but it seems to be OK. Run the following macro before saving the WB in Drive C ----------------...

XmlTextWriter
I am using the XmlTextWriter class to generate some XML however if I try to do something like string str = "cost �500"; xtw.WriteElementString("symbol", str); The � does not get encoded to &#163; like it should. I have tried changing the encoding of it but none of the options (Unicode, UTF8 etc.) perform the encoding correctly. At the moment I have just replaced the above with xtw.WriteStartElement("string"); str = "cost �500"; str = str.Replace("�", "&#163;"); xtw.WriteRaw(str); xtw.WriteEndElement(); Which does the tri...

Two Basic Questions.
Hello, I am new to MS SQL 2K, migrating from MySQL. First of all, this company I just started with has an MS SQL2K database sitting on a windows xp pro machine. We are moving it to MS Sever instead, don't know why it was on XP Pro - bad decision we think. Second, in MS SQL we need to update a field during an insert event. So my two questions are: 1) If we run the script to create the DB on the Server, can we drop the DB and load the original DB from the XP machine? I think this is the correct terminology. 2) We have a column in a table that we need to update via a calcu...

XmlTextWriter.WriteString
Hi, I've been working on a bug in some production software using XmlTextWriter. Basically, I need to but a Surname in an element, the surname in question is O'Connor. Because of the ' I've used the following code: .WriteStartElement("Surname") .WriteString(client.Surname) .WriteEndElement() assuming that the ' would be encoded to &apos;. It isn't!! Am I missing something here? Regards * Gavin Sullivan wrote in microsoft.public.dotnet.xml: >I've been working on a bug in some production software using XmlT...

Date conversion question
Am trying to understand why is that when I have a variable MaxDate (undeclared) and is has a value of 38697 and if I use =TEXT(MaxDate,"mm/dd/yy") I get the correct value of 12/12/09 but if I use function =CDATE(MaxDate) I get 12/11/2005 as an output? Also the format command didn't work either to convert MaxDate with the code =format(MaxDate, "mm/dd/yy") as it also gave 12/11/2005 when the correct output was 12/12/09. I am trying to understand this. Thanks, Chet Assuming you are using XL2003 or lower... if you click to Tools/Options = on the menu bar, th...

Looking for suggestions on usage of Combobox with 50000 items or alternatives?
Loading up a combobox with 50,000 items is slow. Is there an alternative way to handle this situation more efficiently? Thanks. Look at CComboBox::InitStorage. joe On Wed, 2 Jul 2003 23:38:43 -0400, "Charles C." <binstar@aei.ca> wrote: >Loading up a combobox with 50,000 items is slow. Is there an alternative way >to handle this situation more efficiently? > >Thanks. > Joseph M. Newcomer [MVP] email: newcomer@flounder.com Web: http://www.flounder.com MVP Tips: http://www.flounder.com/mvp_tips.htm 50000 items would be way to many for a user to scroll th...

go to page question
How do I move around in a document--namely, how do I go to page x or to page first or page last? Press Ctrl+G. -- Herb Tyson MS MVP Author of the Word 2007 Bible Blog: http://word2007bible.herbtyson.com Web: http://www.herbtyson.com "richard" <rmk@wonderland.net> wrote in message news:ehetEr2fKHA.5608@TK2MSFTNGP05.phx.gbl... > How do I move around in a document--namely, how do I go to page x or to > page first or page last? On 12/17/2009 6:12 PM, Herb Tyson [MVP] wrote: > Press Ctrl+G. > Thank you. But I wonder why I could not find th...

Usage tips
We have MS Money Plus and have just begun using it. My wife and I input our information and uploaded our bank account info and credit card info. So now I'm wondering where to go from here. We only have one months worth of info in Money thus far. How do others use Money? Should we continue to bring in monthly bank and CC info to create a budget? Or, s we purchase something on a CC (for example) do we manually enter this and somehow balance it with the CC statement we import later? Looking for tips on most effective way to get the most out of Money. Suggest that you go and have a lo...

Reference column question
Setting up a tabulation speadsheet,has 40 rows and 10 columns.Question is when I do my formula which is a subtraction for each column,I want to use a refernce # from the first row of each column =Sum(F1-D3)=SUM (G1-D3)and so to=Sum(P1-D3)Rather than enter each manually,because cut and paste adds 1 to each column how can I get to use f1 as reference for that column G1 for that column.Thanx If I understand correctly, try putting a $ in front of the row reference. Also, sum is not necessary for what you are doing. =F$1-D3 as you copy that down it becomes =F$1-D4 copied across to the ri...

DPM Excesive tape usage.
Guys, we moved from a BE environment to DPM. I've noticed that our backups are now taking 2 tapes per day. Our current file server backup, sql backup and apps backup total less than 360gb, and our first and second storage for exchange 2007 have a total of 16gb. That being said it gives me a total of 376gb of tape space needed, which we have. We have a Dell PowerVault 124t LTO-2. 200/400GB. The configuration on the backups is as follows: 1 Protection Group Backup Goals: 1st Backup Goal: Frecuency daily, with 1 week retention. 2nd Backup Goal: Frecuency weekly, with 4 week r...

Question #2
Hello! I'm new to the group and I'm working on an excel sheet. What I'm trying to do is, in a column have a number ex. 36 repeat that number 72 times and on the 73 row increase the number 36 by 1 (to 37). I need to do it about 730 times. I don't know where to start. I've tried to do an auto fill but it's increments by a decimal. The sheet should look like this. Column A 36 36 36 36 36 (72 times) 37 37 37 (72 times) Can anyone help? Thanks, Darrell --- Message posted from http://www.ExcelForum.com/ One way, put in row1 =FLOOR(36+(MOD(ROW(1:1)/73,72)),1)...