[RESOLVED] [2005] Format XML string
I'm trying to format the look of a string from a one line output, like:
XML Code:
<LicenseParameters><RSAKeyValue><Modulus></Modulus><Exponent>AQAB</Exponent></RSAKeyValue><DesignSignature></DesignSignature><RuntimeSignature></RuntimeSignature><KeyStrength>7</KeyStrength></LicenseParameters>
When it should like look this:
XML Code:
<LicenseParameters>
<RSAKeyValue>
<Modulus></Modulus>
<Exponent>AQAB</Exponent>
</RSAKeyValue>
<DesignSignature></DesignSignature>
<RuntimeSignature></RuntimeSignature>
<KeyStrength>7</KeyStrength>
</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.
Re: [2005] Format XML string
Use an XMLTextWriter:
vb Code:
Dim xDoc As New Xml.XmlDocument()
xDoc.Load("C:\Temp\test.xml")
Dim xWriter As New Xml.XmlTextWriter("C:\Temp\Testout.xml", System.Text.Encoding.UTF8)
xWriter.Formatting = Xml.Formatting.Indented
xDoc.Save(xWriter)
IF you want to do it just in memory, you can use a stream instead of the output filename.
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:
Dim xDoc As New Xml.XmlDocument
Dim xString As String = "<myXML></myXML>"
xDoc.LoadXml(xString)
Dim ms As MemoryStream = New MemoryStream
Dim xWriter As XmlTextWriter = New XmlTextWriter(ms, Nothing)
xWriter.Formatting = Formatting.Indented
xDoc.Save(xWriter)
ms.Position = 0
Dim sr As StreamReader = New StreamReader(ms)
Dim xOut As String = sr.ReadToEnd
SyntaxEdit1.Text = xOut