G
Guest
I am just trying create and write to a xml file in my c: drive. I used two
online examples but they don't seem to work. The document is created but
when I open it, nothing is there. Can someone please tell me where I am
going wrong? Get this error:
Cannot view XML input using style sheet. Please correct the error and then
click the Refresh button, or try again later.
--------------------------------------------------------------------------------
XML document must have a top level element. Error processing resource
'file:///C:/xmltest.xml'.
Imports system
Imports System.Xml
Namespace WriteToXML
'This code will be used to create XML using VB .Net
Public Class CreateXMLDoc
Public Overloads Shared Function Main(ByVal args() As String)
As Integer
Try
'Creates the XML text writer to write to XML files and also
creates the document if it does not already exist
Dim writer As New XmlTextWriter("c:\\xmltest.xml", Nothing)
'Starts the new document
writer.WriteStartDocument()
'Add comments
writer.WriteComment("This is a test")
writer.WriteProcessingInstruction("Instruction", "Person
Record")
'Add elements
writer.WriteStartElement("p", "person", "urnerson")
writer.WriteStartElement("LastName", "")
writer.WriteString("Jenkins")
writer.WriteEndElement()
'Add another element
writer.WriteStartElement("FirstName", "")
writer.WriteString("Chris")
writer.WriteEndElement()
'Let's end this document
writer.WriteEndDocument()
'Catch all errors
Catch e As Exception
Console.WriteLine("Exception: {0}", e.ToString())
MsgBox(e)
End Try
End Function
End Class
End Namespace
thanks in advance
online examples but they don't seem to work. The document is created but
when I open it, nothing is there. Can someone please tell me where I am
going wrong? Get this error:
Cannot view XML input using style sheet. Please correct the error and then
click the Refresh button, or try again later.
--------------------------------------------------------------------------------
XML document must have a top level element. Error processing resource
'file:///C:/xmltest.xml'.
Imports system
Imports System.Xml
Namespace WriteToXML
'This code will be used to create XML using VB .Net
Public Class CreateXMLDoc
Public Overloads Shared Function Main(ByVal args() As String)
As Integer
Try
'Creates the XML text writer to write to XML files and also
creates the document if it does not already exist
Dim writer As New XmlTextWriter("c:\\xmltest.xml", Nothing)
'Starts the new document
writer.WriteStartDocument()
'Add comments
writer.WriteComment("This is a test")
writer.WriteProcessingInstruction("Instruction", "Person
Record")
'Add elements
writer.WriteStartElement("p", "person", "urnerson")
writer.WriteStartElement("LastName", "")
writer.WriteString("Jenkins")
writer.WriteEndElement()
'Add another element
writer.WriteStartElement("FirstName", "")
writer.WriteString("Chris")
writer.WriteEndElement()
'Let's end this document
writer.WriteEndDocument()
'Catch all errors
Catch e As Exception
Console.WriteLine("Exception: {0}", e.ToString())
MsgBox(e)
End Try
End Function
End Class
End Namespace
thanks in advance