String representation of XML from System.Xml.XmlTextWriter

Is there anyway to get the XML string representation from the
XmlTextWriter object?
I created a function to create an XML using this object, but I need to
send back an XML as the return value of this function. But I am not
sure how to do this.

    Sub getXML()

        Dim objXMLWriter As New System.Xml.XmlTextWriter(w,
Text.Encoding.UTF8)
        objXMLWriter.WriteStartDocument()
        objXMLWriter.WriteStartElement("firstElement")
        objXMLWriter.WriteStartElement("SecondElement")
        objXMLWriter.WriteElementString("ThirdELement", "Just text")
        objXMLWriter.WriteElementString("ThirdELementL1", "Text
again")
        objXMLWriter.WriteEndElement()
        objXMLWriter.WriteStartElement("sdsd")
        objXMLWriter.WriteAttributeString("timeVisited",
DateTime.Now.ToString())
        objXMLWriter.WriteElementString("ip", "14.23.422.12")
        objXMLWriter.WriteEndElement()
        objXMLWriter.WriteEndElement()
        objXMLWriter.WriteEndDocument()
        objXMLWriter.Close()

    End Sub

Is there anyway to get a string representation from the XmlTextWriter
class???

0
6/2/2007 5:25:30 AM
dotnet.xml 7266 articles. 0 followers. Follow

1 Replies
642 Views

Similar Articles

[PageSpeed] 35

mrdanny2007@gmail.com wrote:
> Is there anyway to get the XML string representation from the
> XmlTextWriter object?
> I created a function to create an XML using this object, but I need to
> send back an XML as the return value of this function. But I am not
> sure how to do this.
> 
>     Sub getXML()
> 
>         Dim objXMLWriter As New System.Xml.XmlTextWriter(w,
> Text.Encoding.UTF8)

First of all, with .NET 2.0 you should usually not use New XmlTextWriter 
but rather use the factory method XmlWriter.Create:
<http://msdn2.microsoft.com/en-us/library/System.Xml.XmlWriter.Create.aspx>

If you want to create a string then you can use an XmlWriter over a 
StringWriter e.g.
   Dim writer As StringWriter = New StringWriter()
   Using xml_writer As XmlWriter = XmlWriter.Create(writer)
and call
   writer.ToString()
at the end to get a string with the XML markup.

-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1778)
6/2/2007 11:25:31 AM
Reply:

Similar Artilces:

Search a string in all worksheets ?
I am searching for a string say ABC in all worksheets in Excel 97. However, it seems that it only allows me to search it in the current worksheet. Is there any suggestion ? Hi Peter............ In XL2k, I just highlighted all three sheets using Right-click on one tab and choosing Select all sheets..........then did Edit > Find > and typed my search string in the window and hit "Find next" repeatedly and it cycled through all three sheets finding the string...........is that what you're wanting to do? Vaya con Dios, Chuck, CABGx3 "Peter" <anonymous@di...

XmlTextReader to a xml string
I want to use FOR XML in my query so I'm going to use the ExecuteXmlReader method? The trouble I'm having now is streaming the results to a string for output as an XML document. Also, since the XML that comes from teh query is not a complete document it's a fragment without a root element. So, any ideas about how to get his into a string? --Buddy Buddy Ackerman wrote: > I want to use FOR XML in my query so I'm going to use the ExecuteXmlReader > method? The trouble I'm having now is streaming the results to a string for > output as an XML document. Also, ...

Missing Security TAb in System Manager on Organisation Level
Hi! What do I have to do to see in the properties of the exchange organisation the SECURITY-TAB on LONDON in the SystemManager ? I wonder why sometimes i see a security tab and sometimes I dont. (on different machines) I seems to be a setting. plz help On Tue, 22 Mar 2005 00:53:02 -0800, Robert <Robert@discussions.microsoft.com> wrote: >Hi! > >What do I have to do to see in the properties of the exchange organisation >the SECURITY-TAB on LONDON in the SystemManager ? > >I wonder why sometimes i see a security tab and sometimes I dont. (on >different m...

XML receipt cache force reload?
I am pulling my hair out over here. I hand editted the XML to place the SubDescription1 instead of ItemLookupCode. I also said for the POS station to prompt for receipts. Even after specifying a new receipt XML file and trying to reload the updated version, it's having difficulty getting used to the new format. It still recalls the old. Can someone advise me as to a surefire way to clear out a cache of receipt info? Thanks, Kevin Fisher Fisher wrote: > Even after specifying a new receipt XML file and trying to reload the > updated version, it's having difficulty getting used...

Save Application State to XML: How to have each module create a "Node"?
Hi, I have an application which is built from many modules. I re-use the modules in different applications. I'd like to have each of my modules implement a "SaveState()" method. The method should return the state of the module (and any modules it contains) in some nice, easily parsable and savable format. I think this format should be XML. So should each module return an XmlElement, an XmlDocument, or an XmlDocumentFragment. I've been experimenting and I can't figure out the best way to do this. I'd like to do it "right" because I'll be doing this a l...

How can you copy selected cells when one cell contains a specified string?
Hi! I need to paste selected cells into different worksheets. The cells contain information like: date, amount, category eg: 24/08/04, 590, eggs 25/08/04, 430, cheese what I wanna do is copy date and amounts to eggs worksheet or cheese worksheet, depending on whether category is eggs or cheese. Is there a way to combine the IF function with a paste link, or something like that? Thanks a bundle in advance! Jon. Formulas return a value to the cells in which they reside. They cannot perform actions, such as copy,paste ect. what you want is possible but you didn't not provide enou...

xml to excel #2
can anybody tell me how to transfer xml data to an excel template (worksheet) using asp.net ? Hi Ganesh, Regarding this issue of transferring the XML datato an excel template, I would request you to please go through teh following article to transfer the data from an access database to Microsoft Office Excel 2003. These include using the user-Interface, programmatically creating an XML file, transforming the data and reading it into Excel, and automating Excel and programmatically reading the data file : [Transfer XML Data to Microsoft Office Excel 2003 with Microsoft Visual Basic .NET] ht...

How do I write a string in the destination element depending on what the string is in the source, using XSLT/XPath? (Like a switch statement.)
Is there something like a switch statement in XPath? What I want to do is this: In the source there is an element called "member" with either the value "0" or "1". In the destination element (also called "member") the value should be "No" or "Yes" (Where "0" corresponds to "No" and "1" to "Yes"). How do I do this? Joakim Olesen wrote: > Is there something like a switch statement in XPath? What I want to do is > this: > > In the source there is an element called "member&quo...

exporting to XML
I noticed that you can export an Access database to XML, but is there anyway you can run it from a macro or a script. I want to automate the process on a nightly basis. thanx I assume access 2003? Check out the application.ExportXML acExportTable While in the code editor, go help...and type in ExprotXML You will find information on the ExprotXML feature.... -- Albert D. Kallal (Access MVP) Edmonton, Alberta Canada pleaseNOOSpamKallal@msn.com http://www.members.shaw.ca/AlbertKallal But keep in mind that exportXML will only export one table from the database. You will ha...

How to find a text in a string without giving the position of the
My requirement are I want to find a particular text in a string with out giving the position of the text . I believe that if we use find and search we have to give the text position for the particular text. Can anyone guide me what should be the function used for getting this. Post example(s) -- Don Guillett Microsoft MVP Excel SalesAid Software dguillett@gmail.com "Sreekanth" <Sreekanth@discussions.microsoft.com> wrote in message news:B2ABF7FC-5745-4863-AA05-4EC1D61C825E@microsoft.com... > My requirement are > I want to find a particular text in...

System attendant mailbox manager report
I'm not sure how to track this one down. I am running Exchange 2003 sp2 on two Exchange servers they function as backends. I keep getting a System attendant email sent to me for a thats says "The Microsoft Exchange Server Mailbox Manager on SCMAIL1 completed processing successfully". This is all good and fine, but what i dont understand is what recipient policy is generating this because when i check my recipient policies none of them are configured for mailbox manager settings, so i dont understand why i keep getting the email and the attached report. Is there a way to ...

Stringing formulas again
Hey there Roger, once again this formula thing is driving me crazy...I can visualize what I want to do but can't work out the formula...This is how I see it in my mind =IF(AI13,AW13,BI13,BW13,CJ13="N","",IF(AI13,AW13,BI13,BW13,CJ13="R","",SUM(AI13+AW13+BI13+BW13+CJ13/100)))) What do you think? Cheers David Perhaps this will help........... =IF(OR(AI13="N",AW13="N",BI13="N",BW13="N",CJ13="N",AI13="R",AW13="R",BI13="R",BW13="R",CJ13="R"),""...

String of strings
Is there a standard way of handling a double null terminated string with embedded null terminated strings. I've looked but can't find any examples. TIA, Gerry Murphy You have to manully put them in string, I believe you are looking for MutliSz reg string or string for shFileOperation if i am not wrong. -- With Regards Alok Gupta Visit me at http://alok.bizhat.com "I Believe this will Help" "Gerry Murphy" <gerrymurphy@rcn.com> wrote in message news:YNydnaPkJaUXCc7fRVn-uQ@rcn.net... > Is there a standard way of handling a...

Read from XML into Datagrid with dropdownlist
I'm reading xml data into a dataset, but I'm struggling to display the data in the way that I'd like to. I would like to generate a datagrid or datalist with two columns. One contains US states, and the other contains dropdownlists or comboboxes, which hold all the counties within its associated state. I appreciate all help that is offered. My xml file looks something like this: <MyDataSet> : : <state name="FLORIDA"> : : : <county>Orange</county> <county>Osceola</county> <county>Polk<...

Count occurance of a string across numerous worksheets
Hi all, Have a "Control Page" and numerous other sheets. I've now listed all workseets on the "Control Page" eg: .. A B 10 Feb04-Mar04 11 Jan04-Feb04 12 Dec03-Jan04 13 Nov03-Dec03 14 Oct03-Nov03 15 Sep03-Oct03 16 Aug03-Sep03 17 Jul03-Aug03 18 Jun03-Jul03 19 May03-Jun03 20 Apr03-May03 21 Mar03-Apr03 22 Feb03-Mar03 23 Jan03-Feb03 24 Dec02-Jan03 25 Nov02-Dec02 Im trying to count the number of times a specific string "Internet Usage - Prepaid IP Hours &q...

Searching for Substrings Within Strings
I would like to be able to search and flag a list of string data based on another list of substring data. If I have a list of strings in Column A and input the list of substrings in Column C, I would like an "X" to appear in Column B every time that a substring mentioned in Column C is included in any of the strings indicated in Column A. (There cannot be multiple instances of the same substring, or a combination of different substrings, in each string of data in Column A.) For instance, given the following information indicated in Columns A and C, the "X" should appear a...

Cheque printout to a file with date & amount converted to text/string
Print cheque output a text file, and this text file will be sent to bank for further processing. There are some fields are hardcoded and some are from GP fields, including date and amount. We modify the Report Writer for the Cheque printing, the added a few of calculated fields. Some calculated fields will contain text with hardcoded data (may contain special characters, like comma and /) Some calculated fields will hold data from the field found in GP and if it is date format, it will be using RW_DateToString() to convert it to string text and this calculated can be showing in...

How do I remove * from text string in cell
I need to remove the asterisk character from a text string within Excel but ordinary find/replace just sees it as a wildcard and deletes everything. Hi Search for ~* and it should work. HTH. best wishes Harald "Sue" <Sue@discussions.microsoft.com> skrev i melding news:15AB8A9C-4C55-4653-94DE-3D2DC2C2BEA8@microsoft.com... > I need to remove the asterisk character from a text string within Excel but > ordinary find/replace just sees it as a wildcard and deletes everything. ...

XSD/XML -> RDB in .Net
Hello all! Are there available samples or code which can create "create table" SQL statements using provided XSD and/or XML? Is it possible to get create table statements from DataSets / DataTables in ..Net? Any ideas how to approach this? ...

POS system in workgroup or domain?
I am looking into getting a POS system for my brother's restaurant since he is not knowledgeable about software/hardware. It is a small restaurant. I am looking at MS, but others also. My question is normally do you guys setup the terminals and server in a workgroup or domain? What is the norm on this. I was just testing a POS software from another company and i set it up in a workgroup. It mentioned mapping to the server from the workstation terminals(running XP) to run the database and services, printer spooler, etc. My problem is that if a savvy enough cashier can find out about the map...

Syntax Error in a SQL string
Can someone spot the syntax error in this SQL string? I tried, but could not see where it is. Thanks in advance, Paulo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Set qdfTemp = CurrentDb.CreateQueryDef("Current Orders Set", _ "SELECT IIf([Orders]![Status]='REC',[Orders]![DC Cims Week Actual],[Orders]![ETA to DC Cims Week]) " & _ "AS RelevantWeek, Sum(Orders.[Order Qty]) AS [SumOfOrder Qty], Sum(Orders.[Received Qty]) AS [SumOfReceived Qty], " & _ "Sum(IIf([Orders]![Channel]='WHOLESALE',IIf(...

RecordsetClone SQL string
I am trying to retrieve the RecordsetClone SQL string form a filtered form. I just can't get a handle on how to do this. Thanks "DataCorp" <kurt @at dataman.cc> wrote in news:Z-WdnQGjTO2On_nanZ2dnUVZ_v-hnZ2d@bresnan.com: > I am trying to retrieve the RecordsetClone SQL string form a > filtered form. > > I just can't get a handle on how to do this. > > Thanks > That's because there is no handle. use the form's recordsource property to determine the name of the query, then go through the querydefs collection to retrieve the SQL. ...

Save Excel File As XML
I'd like to "save as" from Excel to XML format. Works fine but there so much gibberish that gets exported when I try to use in Dreamweaver (Spry component), it only spits out gibberish. Anyone know how to work around this? Or to get Excel to spit out cleaner XML without any handcoding? Thnx, On 1/29/09 4:23 PM, in article C5A78889.9AD5%ronald.m.mochinski@nasa.gov, "Ron Mochinski" <ronald.m.mochinski@nasa.gov> wrote: > I'd like to "save as" from Excel to XML format. Works fine but there so much > gibberish that gets exported when I try to use...

removing xmlns form xml vb.net
Hello, If I have a xml document with a rootlevel <workOrderReleased xmlns="http://www.qad.com/qdoc" xmlns:enc="http://www.w3.org/2002/12/soap-encoding" xmlns:qcom="http://www.qad.com/qdoc/common" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="workOrderReleasedWithComments-JITS17_1.xsd"> When I use the following vb.net code to remove the xlmns attributes they all remove but the first one. I need to remove them all. objXMLDoc.Load(fileString) Dim objAttrib As XmlAttributeCollect...

receipt templates
2 Questions: 1. I'd like to customize some templates but don't know where to start - Is there a Receipt Template/XML customization guide or equivalent that I could download? 2. My cash drawer is connected to my receipt printer and in order to open it I need to send the ascii string: 27,112,0,25,250 to the printer. Is there an xml command I could add to the receipt template that would write this out everytime a receipt is printed? Thanks in advance for your help!!! Check the reports library on Customer Source - IIRC, there is a receipt template that sends ascii commands to the p...