Results 1 to 3 of 3

Thread: [RESOLVED] [2005] Format XML string

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Alaska
    Posts
    435

    Resolved [RESOLVED] [2005] Format XML string

    I'm trying to format the look of a string from a one line output, like:

    XML Code:
    1. <LicenseParameters><RSAKeyValue><Modulus></Modulus><Exponent>AQAB</Exponent></RSAKeyValue><DesignSignature></DesignSignature><RuntimeSignature></RuntimeSignature><KeyStrength>7</KeyStrength></LicenseParameters>

    When it should like look this:
    XML Code:
    1. <LicenseParameters>
    2.     <RSAKeyValue>
    3.         <Modulus></Modulus>
    4.         <Exponent>AQAB</Exponent>
    5.     </RSAKeyValue>
    6.     <DesignSignature></DesignSignature>
    7.     <RuntimeSignature></RuntimeSignature>
    8.     <KeyStrength>7</KeyStrength>
    9. </LicenseParameters>

    Just to note, The data inside the nodes is the only thing that will change. The names and order will always be the same.

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: [2005] Format XML string

    Use an XMLTextWriter:

    vb Code:
    1. Dim xDoc As New Xml.XmlDocument()
    2.         xDoc.Load("C:\Temp\test.xml")
    3.  
    4.         Dim xWriter As New Xml.XmlTextWriter("C:\Temp\Testout.xml", System.Text.Encoding.UTF8)
    5.         xWriter.Formatting = Xml.Formatting.Indented
    6.         xDoc.Save(xWriter)

    IF you want to do it just in memory, you can use a stream instead of the output filename.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Alaska
    Posts
    435

    Re: [2005] Format XML string

    Thanks

    I finally got it working just right. I had to tweak it a little bit, since xWriter creates: <?xml version="1.0"?>


    VB.NET Code:
    1. Dim xDoc As New Xml.XmlDocument
    2.             Dim xString As String = "<myXML></myXML>"
    3.             xDoc.LoadXml(xString)
    4.             Dim ms As MemoryStream = New MemoryStream
    5.             Dim xWriter As XmlTextWriter = New XmlTextWriter(ms, Nothing)
    6.             xWriter.Formatting = Formatting.Indented
    7.             xDoc.Save(xWriter)
    8.             ms.Position = 0
    9.             Dim sr As StreamReader = New StreamReader(ms)
    10.             Dim xOut As String = sr.ReadToEnd
    11.             SyntaxEdit1.Text = xOut

Posting Permissions

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



Click Here to Expand Forum to Full Width