Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

written xml file in one line?!

Status
Not open for further replies.

Bob2

Programmer
Jul 3, 2000
228
SE
Hi


I use this code to write an xml file....

<code>
Sub Page_Load()

' initialize a XmlTextWriter object
Dim objXmlWriter As XmlTextWriter = Nothing

' location to the XML file to write
Dim strXmlFile As [String] = Server.MapPath("testfile.xml")


objXmlWriter = New XmlTextWriter(strXmlFile, Nothing)

' start writing the XML document
objXmlWriter.WriteStartDocument(False)

' start with the root element
objXmlWriter.WriteStartElement("library" & vbCrlf)

' first child element
objXmlWriter.WriteStartElement("book", Nothing)

' add an attribute
objXmlWriter.WriteAttributeString("bkid", "MF01")

' some text
objXmlWriter.WriteElementString("title", "XML and ASP")

' back to the root element
' closing each element written above
' one at a time
objXmlWriter.WriteEndElement()
objXmlWriter.WriteEndElement()

' flush the object and write the
' XML data to the file
objXmlWriter.Flush()


' Close the XMLWriter object
If Not (objXmlWriter Is Nothing) Then
objXmlWriter.Close()
End If
End Sub 'Page_Load
</code>



But everything is written as one line, how can get the different elements on seperate lines?



Regards

M
 
objXmlWriter.Formatting = Formatting.Indented
objXmlWriter.Indentation = 4

 
Hi


Thanks a lot!


Regards


M
 
BTW, XML doesn't care about making it look pretty. The parsers are perfectly happy with reading the contents off one line vs. one line per element. Adding whitespace just bulks up the file (if you're sending this over a network or the Internet, it will slow your responsetime).

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top