473,378 Members | 1,347 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,378 software developers and data experts.

Easiest way to build a xml fragment (write to string)

Hi, can anyone tell me

1) what is a easy way to build a xml fragment into a string. I don't what
the fragment to be written to file, just in a string will be fine.

I can build the xml fragment with the xmlTextWriter, but I don't want to
write to a file. But using methods like WriteStartElement,
WriteAttributeString is very handy.

Of course I can build the string with the stringbuilder but this is not a
xml-friendly and secure way. The xml fragment will be something like:

<houses>
<house houseid="1" typeid="2" />
<house houseid="2" typeid="3" />
</vakken>

2) I even don't want a "<?xml version="1.0"?>" line. How to suppress this?

Can someone advice me?
VS2005-VB.NET
Regards Coen.
Jun 21 '07 #1
2 4444
Hello,

you can use the XmlWriter and write to a String using the StringWriter. But
this will force yout encoding to UTF-16. If you need another encoding, use
the StreamWriter and write to a MemoryStream.

Best regards,
Henning Krause

"Coen" <cb*****@newsgroup.nospamwrote in message
news:17**********************************@microsof t.com...
Hi, can anyone tell me

1) what is a easy way to build a xml fragment into a string. I don't what
the fragment to be written to file, just in a string will be fine.

I can build the xml fragment with the xmlTextWriter, but I don't want to
write to a file. But using methods like WriteStartElement,
WriteAttributeString is very handy.

Of course I can build the string with the stringbuilder but this is not a
xml-friendly and secure way. The xml fragment will be something like:

<houses>
<house houseid="1" typeid="2" />
<house houseid="2" typeid="3" />
</vakken>

2) I even don't want a "<?xml version="1.0"?>" line. How to suppress this?

Can someone advice me?
VS2005-VB.NET
Regards Coen.
Jun 21 '07 #2
Hi Coen,

For creating some XML fragment, you can use both XmlWriter or XMLDocument
(DOM approach). And for your request that you want to save the XML fragment
into a string object, you can simply use a StringWriter instead of a
StreamWriter so that the output of XmlWriter or XmlDocument can be held in
a string in memory instead of flush to file system.

Please feel free to post here if you have any further questions or concerns.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 22 '07 #3

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

Similar topics

5
by: Christian Seberino | last post by:
In c extension what is easiest way to build a (PyObject) list from an array of doubles? I don't think I can do "return Py_BuildValue(...) to make a list from an array can I??? How else can I...
10
by: Douglas Buchanan | last post by:
I am using the following code instead of a very lengthly select case statement. (I have a lot of lookup tables in a settings form that are selected from a ListBox. The data adapters are given a...
2
by: gu4y | last post by:
Hello All, What's the most efficient way to do this? I would like to load an xml file like this: <?xml version="1.0" encoding="utf-8" ?> <strings> <section key="1"> <string>sdfa</string>
7
by: Scott M. Lyon | last post by:
Quick (hopefully easy) question for you guys. What is going to be the quickest/easiest way to generate XML from VB.NET? Note: I don't mean an XML file, but XML in memory somehow (an...
0
by: NotGiven | last post by:
I would like to build a "store" offering products related to my web site. Only when they are ready to check out are they sent to amazon.com. Amazon only has examples for Pearl, Java and .Net. I use...
6
by: dotnetnoob | last post by:
i would like to know how i can build xpath expression dynamiclly. let's say i have a following xml file: <EventEnrollment InstanceNumber = "675"> <EventSource> <ObjectReference...
0
by: Sky | last post by:
Hello: I'm trying to emulate the userSettings storage system on CE. XmlSerialization looks like a very useful 1-line solution that looks wonderful for serializing one class to one xml document...
1
by: dasilva109 | last post by:
Hi guys I am new to C++ and need urgent help with this part of my code for a uni coursework I have to submit by Thursday //ClientData.h #ifndef CLIENTDATA_H #define CLIENTDATA_H #include...
2
by: lee | last post by:
Newbie question: I'm looking for the easiest way to run SQL statments in Access. I'm getting confused by th GUIs - I'm just looking forhow to run SQL on a table- thanks
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.