473,395 Members | 1,623 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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???

Jun 2 '07 #1
1 7754
mr*********@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/
Jun 2 '07 #2

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

Similar topics

5
by: Alessandro | last post by:
Hi ! I have a big problem, i'm using XMLdocument to add elements to a XML file. Elements are like this: <name>Paolo</name> <comment>this is <a comment></comment> <description>In italian "is"...
3
by: Chrigel | last post by:
Hi all, We have problems deseralizing objects previously serialized as XML. This did work fine with .NET 1.1 but since we have installed SP1, deserializing fails (but serializing works). The...
1
by: Yuriy | last post by:
Hi, Can anybody explain the following? Say I have the following source XML and XSLT (see below). No matter what this XSLT does. It is just a sample to show a problem. the idea is that XSLT...
1
by: John | last post by:
I can't find any solution to store a new created XML with XmlWriter to String. It requires a Stream Thanks John
4
by: Tarren | last post by:
Hi: My serialized class is ending up in a XML.XMLTEXTRIDER How do I write from that to a string? It seems as if it is storing it as a stream? How do I read the contents of a stream into a...
3
by: Tosch | last post by:
I have successfully been using XMLTextWriter to write XML to a file. But how to I write XML to a string which I can then use to store in a database? Tosch
17
by: Modica82 | last post by:
Hi All, I am very new to web services, so am struggling to understand exactly what I am doing with regards to its returns etc. I have been given the task of designing and developing a web...
6
by: Steven Nagy | last post by:
HI, This all applies to a project in the compact framework (Pocket PC). I need to convert a dataset object into XML which I will then send out via TCP. In a standard app I would do this as...
1
by: vinki | last post by:
Hi Everyone, I am constructing an xml file, but when I try to read it there are some extra slashes in the output. Can anoyone tell me why there are some extra slashed and can i send the file to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.