473,545 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XmlDocument object to string - plase help with unusual character!

Hi everyone,

Hope you can help me. I'm converting an XMlDocuemnt object to a
string. I use the following code:
Dim doc As New XmlDocument

'Convert XmlDocument object -> String
Dim ms As New System.IO.Memor yStream
Dim xtw As XmlTextWriter = New XmlTextWriter(m s, Encoding.UTF8)
doc.Save(xtw)
Dim bytes() As Byte = ms.ToArray()
Dim st As String = Encoding.UTF8.G etString(bytes)
Only problem is though - when I debug the code it inserts a little
unusual character at the start of the xml string. It looks like a
little box in the "yellow" window and when I print it it looks lioke a
little dot. This strange character is making hte XML invalid.

Anyone with any ideas/suggestions/comments/code-snipets that can help.
Would greatly appreciate any assistance - I'm at my wits end.

Al.
The confused!

Mar 14 '06 #1
3 1707
Almurph,

Can you try this one on our website, which works forever smooth

http://www.vb-tips.com/default.aspx?...c-61641f5c8d9d

If it is a dataset than you can try this one.

http://www.vb-tips.com/default.aspx?...a-c891846eaf0b

I hope this helps,

Cor
<al*****@altavi sta.com> schreef in bericht
news:11******** **************@ i39g2000cwa.goo glegroups.com.. .
Hi everyone,

Hope you can help me. I'm converting an XMlDocuemnt object to a
string. I use the following code:
Dim doc As New XmlDocument

'Convert XmlDocument object -> String
Dim ms As New System.IO.Memor yStream
Dim xtw As XmlTextWriter = New XmlTextWriter(m s, Encoding.UTF8)
doc.Save(xtw)
Dim bytes() As Byte = ms.ToArray()
Dim st As String = Encoding.UTF8.G etString(bytes)
Only problem is though - when I debug the code it inserts a little
unusual character at the start of the xml string. It looks like a
little box in the "yellow" window and when I print it it looks lioke a
little dot. This strange character is making hte XML invalid.

Anyone with any ideas/suggestions/comments/code-snipets that can help.
Would greatly appreciate any assistance - I'm at my wits end.

Al.
The confused!

Mar 14 '06 #2

The character is the Byte Order Mark (BOM) - don't have a reference to
hand but a web search will give you more information if interested

To prevent the writer emitting it you can use

Dim encoding As New System.Text.UTF 8Encoding '
the default false arg for the ctor suppresses the BOM
Dim xtw As XmlTextWriter = New XmlTextWriter(m s, encoding)

.....

Dim st as string = encoding.GetStr ing(bytes)
hth,
Alan.

Mar 14 '06 #3

AlanT wrote:
The character is the Byte Order Mark (BOM) - don't have a reference to
hand but a web search will give you more information if interested

To prevent the writer emitting it you can use

Dim encoding As New System.Text.UTF 8Encoding '
the default false arg for the ctor suppresses the BOM
Dim xtw As XmlTextWriter = New XmlTextWriter(m s, encoding)

....

Dim st as string = encoding.GetStr ing(bytes)


Alan,

Thanks a million - I never heard of the BOM before. I love it when I
learn something new. Thank you both for your comments.

Merci,
Al.
The happy one.

Mar 16 '06 #4

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

Similar topics

1
17109
by: Martin Honnen | last post by:
With both .NET 1.0 and 1.1 I have found the following strange behaviour where System.Xml.XmlDocument.LoadXml doesn't throw an error when parsing a text node with a character reference to an invalid characters like &#x1;. Using the CreateTextNode method I create a text node containing "\u0001a" (C# string literal notation). As far as I...
4
4833
by: Robert Rossney | last post by:
I'm trying to send and receive XmlDocument objects using the System.Messaging.dll functions. The code I've written follows, as best I can tell, the methodology used in the sample code for the XmlMessageFormatter class. But it isn't working -- specifically, receiving isn't working. What am I doing wrong here? I begin by creating a...
2
1510
by: Adam Smith | last post by:
Hello, I have a file: test.txt: <?xml version="1.0" encoding="UTF-8"?> <First> <value>3</value> </First> I am reading it like this:
1
3023
by: AJ Brown | last post by:
I'm loading an XmlDocument object from a string using LoadXml. The string is a well-formed XML fragment (see example) and loads fine, however there are entities (&amp;) within attribute values. The loader parses the incoming entities and converts them to their character references automatically. How would I retain the entity? Example incoming...
1
3532
by: Chief | last post by:
I am unable to load an xml document that contains Chinese characters in an attribute value. I need to load the document into and XmlDocument object and am using the XmlDocument.Load(string filename) method. I get an error that says the document contains invalid characters. The document loads fine with Chinese characters in a node value, but...
19
78773
by: Paul | last post by:
hi, there, for example, char *mystr="##this is##a examp#le"; I want to replace all the "##" in mystr with "****". How can I do this? I checked all the string functions in C, but did not find one.
1
3621
by: Joe Monnin | last post by:
I have a web service that takes an XmlDocument as a parameter, performs some processing on it, and saves it to a database. The web service signature looks similar to this: public void SaveDocument(XmlDocument doc) { //Method logic omitted } The web service worked great in .net 1.1, but upon upgrading to .net 2.0 IIS
2
13564
by: John Smith | last post by:
I'm writing webervice client using .Net 2.0. I have this class: public class MyWebService : SoapHttpClientProtocol { public XmlDocument validate(string url, XmlDocument xmlDocument) { this.Url = url;
2
4435
by: Manikrag | last post by:
Hi All, I am getting error while am loading RSS Stream in XMLDocument object. The error is as follows. "System.Xml.XmlException: '', hexadecimal value 0x19, is an invalid character. Line 18, position 32." I understand that this is becasue I have one apostrophe in the RSS Feed. I have tried few tricks to get rid of apostrophe but of no...
0
7486
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7416
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7676
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7932
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7442
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7776
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6001
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4965
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3473
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...

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.