Results 1 to 2 of 2

Thread: writing XML Confusion...

  1. #1
    kantplayalik is offline VB.NET Forum Newbie
    .NET Framework
    .NET 1.1 (VS 2003)
    Join Date
    Mar 2006
    Posts
    7
    Reputation
    0

    Question writing XML Confusion...

    Do any of you guys/girls out there know how to rewrite this code to work with the xmlTextWriter class? I need to re-create a document similar to this but preserve the formatting. Any help or ideas would be much appreciated. Thanks in Advance.

    Dim sw As New StreamWriter(New FileStream("Results.xml", FileMode.Create))
    Dim xmltw As New XmlTextWriter(sw)
    Dim reader As XmlTextReader = New XmlTextReader("books.xml")

    Do While (reader.Read())
    Select Case reader.NodeType
    Case XmlNodeType.Element 'Display beginning of element.
    Console.Write("<" + reader.Name)
    If reader.HasAttributes Then 'If attributes exist
    While reader.MoveToNextAttribute()
    'Display attribute name and value.
    Console.Write(" {0}='{1}'", reader.Name, reader.Value)
    End While
    End If
    Console.WriteLine(">")
    Case XmlNodeType.Text 'Display the text in each element.
    Console.WriteLine(reader.Value)
    Case XmlNodeType.EndElement 'Display end of element.
    Console.Write("</" + reader.Name)
    Console.WriteLine(">")
    End Select
    Loop
    Console.ReadLine()

    End SubI know i need to use the methods like writeStartElemnt, writeElementString, writeAttributeString, etc.
    I'm just confused as to where to use what.

  2. #2
    m_ogden is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 1.1 (VS 2003)
    Join Date
    Mar 2006
    Location
    New Hampshire
    Posts
    74
    Reputation
    91
    There are some good examples in MSDN:
    http://msdn.microsoft.com/library/de...classtopic.asp

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking