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
817 Views

Similar Articles

[PageSpeed] 27

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 (1777)
6/2/2007 11:25:31 AM
Reply:

Similar Artilces:

Creation of XSD from XML
Hi Is there an easy way to programmtically create an xsd-schema from an xml file? Reason .... I create slightly different xml documents in my app, based on user data. I would like to create a temporary schema files from those xml documents, in order to use the data in a UI grid. I found the XmlSchema class, but it would be an overkill to create the schema through this class. Thanks for any hints, Urs Urs wrote: > Is there an easy way to programmtically create an xsd-schema from an xml > file? ..NET 2.0 has an InferSchema method of the XmlSchemaInference class in System....

Warning when saving XML Spreadsheet 2003 with Excel 2007
I'm using Excel 2007 to edit an XML Spreadsheet 2003 file. Every time I save the file it pops up a warning dialog saying that some features may not be supported. I know I'm not using any features that the XML Spreadsheet doesn't support so is there any way to disable the warning? It's very annoying. And would be even more annoying if the saved the file only to find some features had been lost The computer is a tool ; users have to do the work best wishes Bernard "Ken Paulson" <ken@drunkenhyena.com> wrote in message news:uO0QlBgoKHA.404...

SOAP xml
Fedex in the US is changing their method of dealing with their servers for submitting packages, tracking , etc. The old method was a formatted Xml file submitted via an HTTP Post. You then parsed the returned Xml that contained the information requested. Now they are phasing that out in favor of a web service using WSDL SOAP messages. I took one of their VB.Net samples and have sucessfully tracked packages and received Proof of Delivery Pdf files. However I have a problem when I deal with Fedex tech support when I have questions about some of their other services, for example Address ...

Exchange system manager
I have upgraded to exchange 2003 and use a email redirector on a seperate server for mobile device users to receive email. This redirector server has an older version of the exchange system manager. I nned to upgrade this to match the mapi32 profile. I have tried to use the exchange cd and install the support tools but this will only let me install tools for exchange 5.5 How do I upgrade the system manager on a win 2k server to work with win 2k3 exchange/server? Thanks for your efforts!!! When you stick in the E2K3 cd, under the component selection, under System Tools, choose R...

Boot-start of system driver(s) failed to load
My event log keeps showing error 7026, The following boot-start or system start driver(s) failed to load ftsata2. Could someone please help me with this? ...

make query from to 64 bit system
I have a application need to be compile for 64 bit system. how can i read data from vb.net 2005. hi Jennifer, On 09.12.2009 17:36, Jennifer wrote: > I have a application need to be compile for 64 bit system. how can i read > data from vb.net 2005. First of all, I don't see the point why you're asking this question in an Access newsgroups. Further more, you should really be more spefific... mfG --> stefan <-- ...

LINQ to XML and Amazon Webservices
Hi, I'm having a hard time in using LINQ on XML returned from Amazon Webservices. I'm using the 2008 beta 2 on an XP machine. the code I'm using is: ========= Dim s As String s = "http://ecs.amazonaws.com/onca/xml?" & _ "Service=AWSECommerceService&" & _ "AWSAccessKeyId=1234&" & _ "AssociateTag=my-tag&" & _ "ResponseGroup=Small&" & _ "Operation=ItemSearch&" & _ ...

Searching in a column of strings
Hi I try to find how many cells have a sequence of charcters. From Cell A1:A50. Exemple for "NY" : cellA1 = NY123 cellA2 = NY3235 cellA3 = NY5434 cellA4 = LA4234 function(NY) = 3 Like Seach but instead to be in a single cell, it's in a sequence of cell? Thanks Jack Jack =COUNTIF($A:$A,"*NY*") Regards Trevor "Jack" <anonymous@discussions.microsoft.com> wrote in message news:348501c3fd71$700c6c60$a001280a@phx.gbl... > > Hi > > I try to find how many cells have a sequence of > charcters. From Cell A1:A50. > > Exe...

Problem displaying string data in Edit box
Hi, I am trying to display a CString in an Editbox. In the dialog, I have set the edit box to multiline, read-only, auto vertical scroll and want return. I set the Edit box with the CString variable when a serial handler occurs. The serial handler code is obtained from http://www.codeproject.com/KB/system/serial.aspx and have integrated into my main dialog. I have created a edit box variable in my dialog and create a member variable within the main dialog window. When the serial handler is called, I store the serial message into the CString variable and use SetwindowText() to display the st...

System.Web.Services.Protocols.SoapException
Has anyone tried the Samples that come with the Webservices install? Has anyone else received this error with the Samples or does anyone know what is causing it? "System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> An exception occurred that the exception subsystem was unable to log. Consult your System Administrator.\r\n at CustomerUpdate.WebServiceManager.GetAllCompanies() in C:\\Program Files\\Microsoft Dynamics\\GPWebServicesSDK\\v9\\Samples\\UpdateCustomers\\CustomerUpdate\\WebServiceManager.cs:line 108\r\n at CustomerUpdate.Custom...

Conditional Formatting VBA with formula to find string
Hi, Please can I get some help.... I need to create a conditional format VBA in Excel 2007 (because I have many conditions to include) and I don't know how to do it... The Action Required: If Product A appears in any text string in range($C$95:$C$300) then colour that cell RED, if Product B appears anywhere in a text string within range($C$95:$C$300) then colour that cell BLUE, if Product B appears anywhere in a text string within range($C$95:$C$300) then colour that cell GREEN, and so on through 41 products... Data - I have a list of about 41 Product names in range Z...

Chunking out data from a huge xml file (Ajax)
Hi I am faced with quite a challenge. I need to open a 70-100 meg file and be able to chunk it out using AJAX back to the client but that isn't my problem really. What I need to do is open the file and get pieces of it out without loading the entire thing into memory. The pieces themselves are random although of a fixed size. If I tried to read an entire file into a stirng and parse pieces out I use too much memory and if I use the xmlTextReader and the skip method my memory problems are solved but it creates a huge performance issue. If I don't have to I don't want to ...

Undeliverable messages from System Administrator
I have Outlook 2002 setup with an Imap account and an LDAP directory server. There are two .pst files - one for the local personal folders named outlook.pst (including default Inbox, contacts, sent messages, calendar etc) and another one for the imap account named imapaccount.pst that is basically a cache of messages on the actual server. Everything seems to be working fine except when a message is sent to an invalid account in the LDAP directory. I get a message from System Administrator in the Inbox of my Personal Folders (not the Inbox of my imap account folder that I monitor) with subject ...

About XML scheme
Hi ! What is XML scheme ? What is a use of that ? Give me some idea... Thanks & Regards Elankathir, B'lore, India. *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! ElanKathir .S.N <elankathirctech@yahoo.co.in> writes: > What is XML scheme ? Is an XML based standard to describe the structure of an XML document (more powerful than DTD) > What is a use of that ? Try to start with a tutorial: http://www.w3schools.com/schema/default.asp -- Lawrence "Avevo Halo, poi e` arrivata la mia fidanza...

XML Format
I am looking for documentation on the XML format required to import Vendors into Great Plains and to import Vendor invoices into Great Plains. Is this documented somewhere? I already have the format for Sales but can't find the format for these types of transactions and vendor information. Our requirements are very simple and we do not need the enhanced features of Integration manager. Jean, Using what to import with? The only "built in" tool to GP is the Import Utility which only takes a flat csv or tab file and not XML. So I'm pretty sure that isn't what ...

xml question?
what is the equivalent of this in C# ? foreach (XmlNode xmlConfigNode in xmlConfigDoc["configuration"].ChildNodes) Thansk Sorry I made a mistake here is what I want to convert to C# For Each Node In XmlDocument.Item("configuration").Item("appSettings") "Ray5531" <Ray5531@microsoft.com> wrote in message news:elPIiezOFHA.3408@TK2MSFTNGP14.phx.gbl... > what is the equivalent of this in C# ? > > foreach (XmlNode xmlConfigNode in > xmlConfigDoc["configuration"].ChildNodes) > > > > Thansk > > Hi Ray,...

is Retail Management System(RMS) been used at cafeterias?
Is Ms Retail Management System been used at cafeterias? It might work in a small operation. But is it the right fit? Not in my opinion. Other software is more cafe' friendly and made for the task. If you have a small cafe, in a retail store you might consider it, if your menu does not need to print on remote kitchen printers, and your using RMS for retail. Other wise look at Dinerware perhaps or software designed for restaurants. mt "D. Reveron" <D. Reveron@discussions.microsoft.com> wrote in message news:9D79643B-B9BF-4DD2-96F2-B49D5BCFD5C7@microsoft.com... ...

formula to add a number to a long string **
I'm not quite sure how to best describe this: I need a formula that will take the example below and return the "final result" Col. A = 24.43.234.555 and Col B= 23 making Final Result = 24.43.234.578 Is there a way to do this? This seems to work: =LEFT(A1,LEN(A1)-3)&(RIGHT(TEXT(A1,"0"),3))+23 HTH, Ryan--- -- Ryan--- If this information was helpful, please indicate this by clicking ''Yes''. "MMangen" wrote: > I'm not quite sure how to best describe this: > > I need a formula that will take the e...

Serializing object to XmlDocument (or string)
I am on .NET 2.0 and am trying to serialize an object to an XmlDocument (or a string which I can then create an XmlDocument from). What I have so far is (User is my class); XmlSerializer x = new XmlSerializer(typeof(User)); MemoryStream memStream = new MemoryStream(); How can I get this to a string or an XmlDocument? The serialization works fine as if I serialize to a text file (using StreamWriter), everything looks fine. I've try converting to bytes, reading on XmlWriter, but nothing seems to work. Thanks, ...

XML XSL FO PDF
Can I use XML->XSL->FO->PDF in .NET? I have the XSL FO from XML, and now use client based FOP software. I have seen a few commercial packages for FO->PDF but they are costly (1000 dollars). news wrote: > Can I use XML->XSL->FO->PDF in .NET? Sure but only with some third-part library. .NET doesn't support XSL-FO natively. -- Oleg Tkachenko [XML MVP] http://blog.tkachenko.com I am using FOP which I downloaded from somewhere (forgotten), can you recommend anything for the FO handling? I found the XSL a dream in .NET and hoped that .NET had something intrinsic ...

Escape codes embedded in XML
Hello, I have built an XMLDocument object instance and I get the following string when I examine the InnerXml property: <?xml version=\"1.0\"?><ROOT><UserData UserID=\"2282\"><Tag1 QID=\"55111\"><Tag2 AID=\"5511101\"></Tag2></Tag1><Tag1 QID=\"55112\"><Tag2 AID=\"5511217\"></Tag2></Tag1><Tag1 QID=\"5512282\"><Tag2 AID=\"551228206\"></Tag2></Tag1><Tag1 QID=\"55114\"><Tag2 AID=\"5511406\"></Ta...

Syntax to write a null value inside a sql Insert string?
Is there a way to represent the null value as a string (destination: varchar column) the way that the following string represents a null value for a date? Public Const cNullDate As Date = #12:00:00 AM# Writing to an Access 2003, (conversion) table with VS2005 in VB.NET. Within the table is a field named VSubType1 with a validation rule of: "In ('P','O') Or Is Null" The declare/move/insert statements look like this (shortened example): Dim intRecNbr As Integer = 0 Dim VSubType1 As Object (defined as Text 1 column in Access) Dim V1...

How to create EXE having some XML files ?
Hello there I am designing one application that would create one exe and pack some resources in it(Like some XML files). Is there any way to do this ? If you are unable to understand it, please Let me know. I'd try to elaborate on it more. ...

MSXML2 to Load xml document using ISO-8859-1 encoding
HI My application connects to the UPS server which returns an ISO-8859-1 encoded XML response. I need a part of this response, ie. the AccessLicenseAgreement , which i need to display in my application and then return to the UPS server with the next request. Their server matches what they sent me with what i return back to them. Due to the difference in the encoding method it returns an Invalid AccessLicenseAgreement error back to me. I set my request Processing Instruction to ISO-8859-1 encoding, but i still get the same error from them. I am guessing the problem is when i read it in using Lo...

System Volume Information
Hello , Could someone tell me how to access " System Volume Information " ? TIA , D. xp sp3 i.e. 7 o.e. 6 You have to use the security tab to add your user name to those allowed access. Read this: [How to gain access to the System Volume Information folder - Microsoft] http://support.microsoft.com/kb/309531 "D." <wdstk@sover.net> wrote in message news:e5Wr3oCrKHA.3408@TK2MSFTNGP06.phx.gbl... > Hello , > Could someone tell me how to > access " System Volume Informatio...