Hi,
I’m trying to create a simple xml structure using the XMLWriter in visual basic for the purpose of creating an html page based on user input.
Here’s an example of what I’ve got so far:
Dim writer As XmlTextWriter
writer.WriteStartElement("main")
writer.WriteStartElement("test1")
writer.WriteStartElement("test2")
writer.WriteEndElement()
writer.WriteEndElement()
writer.WriteEndElement()
MsgBox(writer)
I’m getting the following error:
Nullreferenceexception was unhandled
Object reference not set to an instance of an object.
Can someone help me get past this please?
Also I guess I should ask, am I doing this the best way, any other suggestions are welcome, but I would also like to learn how to do it this way as (To my knowledge) this way doesn’t require you to create a whole document.
Thanks.
Steve
Wouldn’t you need to save it to a file, before using it?
dim writer as XMLTextWriter
writer = new XMLTextWriter(Server.MapPath("Data.xml"), nothing)
I’m sure that’s how you are supposto use the TextWriter object. Because you would need to write it, and then use a reading object to show the xml file.
EDIT: You might need to use the: XMLDocument object instead.
Using the XmlTextWriter is fine, but you need to set the output. To a FileStreamWriter or Outputstream.
Also do not forget:
writer.WriteStartDocument() and WriteEndDocument()
Here’s what I’ve got so far, but I’m getting no output:
Dim writer As XmlTextWriter
writer = New XmlTextWriter("C:\\Documents and Settings\\Steve\\Desktop\\Visual Basic Stuff\\image gallery creator test\\images\ est.xml", Nothing)
writer.WriteStartDocument()
writer.WriteStartElement("main")
writer.WriteStartElement("test1")
writer.WriteStartElement("test2")
writer.WriteEndElement()
writer.WriteEndElement()
writer.WriteEndElement()
writer.WriteEndDocument()
I don’t think I’ve fully understood your advice.
I don’t see why I can’t just “tostring” the writer and see/use the output