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

problem with WriteAttributeString

I try to write out some data to an xml file but it stopped with the message

"An unhandled exception of type 'System.InvalidOperationException' occurred
in system.xml.dll

Additional information: Token StartAttribute in state Prolog would result in
an invalid XML document."

The code is as follow

Sub writeXML(ByVal posted As String, ByVal messagetext As String, ByVal
filename As String)

Dim xmlTW As New XmlTextWriter("..\Watcherlog.xml", Nothing)

With xmlTW

.WriteStartDocument()

.Formatting = Formatting.Indented

.WriteComment("Watcher Log")

.WriteAttributeString("Postdate", posted)

.WriteElementString("text", messagetext)

.WriteElementString("Filename", filename)

.WriteEndElement()

.Flush()

.Close()

End With

End Sub

The posted variable where the error appears has a

Now.ToString() as a value generator.

PetterL


Nov 12 '05 #1
1 3904
OK I found the error; I think it should have been pointed out by now that my
code was missing the .writeStartElement () if someone had read this message
in this group.

PetterL:

"petterl" <pe**********@hotmail.com> wrote in message
news:ev**************@TK2MSFTNGP15.phx.gbl...
I try to write out some data to an xml file but it stopped with the message

"An unhandled exception of type 'System.InvalidOperationException'
occurred in system.xml.dll

Additional information: Token StartAttribute in state Prolog would result
in an invalid XML document."

The code is as follow

Sub writeXML(ByVal posted As String, ByVal messagetext As String, ByVal
filename As String)

Dim xmlTW As New XmlTextWriter("..\Watcherlog.xml", Nothing)

With xmlTW

.WriteStartDocument()

.Formatting = Formatting.Indented

.WriteComment("Watcher Log")

.WriteAttributeString("Postdate", posted)

.WriteElementString("text", messagetext)

.WriteElementString("Filename", filename)

.WriteEndElement()

.Flush()

.Close()

End With

End Sub

The posted variable where the error appears has a

Now.ToString() as a value generator.

PetterL

Nov 12 '05 #2

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

Similar topics

2
by: Bill | last post by:
I'm trying to write out an XML file from VB and have it mostly done, but I need the following header and can't seem to get the right syntax for the WriteAttributeString methods to get this result....
4
by: vikas | last post by:
Hi I want to create following xml document using xmlwriter <?xml version="1.0" ?> - <epps> - <remit_trn type="technical"> <remit_date_dtm dtm = "201" >test</remit_date_dtm>...
5
by: Adam Rothberg | last post by:
The following code sample should produce a valid xml file to the console. However, when I try this in C# (Visual Studio 2003, 1.1 Framework), there is an extra questionmark preceding the rest of...
2
by: Danny Springer | last post by:
I am trying to create the following xml file with VS 2005: <?xml version='1.0' encoding='utf-8'?> <SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings"...
0
by: DellaCroce | last post by:
I am generating the following error - "Token StartAttribute in state Content would result in an invalid XML document" with the following code in VB.Net 2003 'Write XML record Dim ls_TradePath...
2
by: Mori | last post by:
I am using the following code to manufactue xml using xmltextwriter. The xml is okay except for the extra set of start document and the outer <string> element. Where do they come from and how do...
0
by: ACC | last post by:
Hi! I'm new around xml and xslt... I'm trying to write a dataset to a CSV file. I'm doing like this: I'm creating a Stylesheet: writer is a XmlTextWriter. (...) // xsl-template...
2
by: fmancina | last post by:
Hi, I am employing the XmlTextWriter class to generate an XML document. Everything works fine, until I have to write an attribute to an element which contains a value. Examples below: //...
3
by: dhurwitz | last post by:
I am trying to create an XML spreadsheet for use with Excel. I first saved a simple spreadsheet as an XML file, and now I am trying to recreate that file in code, using .NET 2.0. The beginning of...
0
by: schlumpfger | last post by:
Hi, IŽd like to create a XML Header like this: <?xml version="1.0" encoding="utf-8"?> <XDOMEA xmlns="http://www.xdomea.de" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"...
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:
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...
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...
0
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,...
0
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,...
0
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...

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.