Groups | Blog | Home
all groups > dotnet xml > january 2005 >

dotnet xml : problem with WriteAttributeString



petterl
1/19/2005 11:39:15 AM
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



petterl
1/20/2005 9:30:56 AM
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:

[quoted text, click to view]

AddThis Social Bookmark Button