- fmronan - 2012-03-06 14:04
I'm intresting for my skin
- phil65 - 2012-03-06 14:12
one question to jmarshall before releasing: which encoding should i set: unicode or ASCII?
got batch converting implemented now i´m starting to like Visual Basic
- spiff - 2012-03-06 14:17
an alternative, and imo better solution than a platform dependent visual basic application, would be to use a xslt transformation. don't have time to give an example right now but google around..
- Hitcher - 2012-03-06 14:17
ANSI or UTF-8?
- phil65 - 2012-03-06 15:28
spiff Wrote:an alternative, and imo better solution than a platform dependent visual basic application, would be to use a xslt transformation. don't have time to give an example right now but google around..
I agree that multiplatform would be nicer, but after googling around I decided that VB would be the easiest for me. (I´m no programmer)
and since this is a one-time-use tool, i hope it´s ok to release it windows-only.
- spiff - 2012-03-06 23:26
Heh of course that is okay, it's not like I have any saying in that. Just giving an option and a opinion.
- fmronan - 2012-03-06 23:51
Quote:i hope it´s ok to release it windows-only.
so that's not for me
- phil65 - 2012-03-07 01:20
fmronan Wrote:so that's not for me
then send me your files, I´ll convert them for you.
- phil65 - 2012-03-07 02:12
is this enough for an UTF- 8 Header?
Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
- phil65 - 2012-03-07 02:49
Ok, here it is 
http://www.gtwf-koeln.de/xmlconvertgui.exe
Please report bugs, missing tags etc...
feedback is always welcome.
current limiitations:
does net convert <posx>400r</posx> for example
no conversion of attributes (for example for animation and border tags)
seems to hang when adding a lot of files... just wait a bit
made some changes some minutes ago, i hope everything works ok.
and here´s the code
Code:
Imports System.Xml
Imports System.Text
Imports System
Imports System.IO
Public Class Filechooser
Public strOutputFolder As String = ""
Public StrArray As String() = {"posx", "posy", "width", "height", "textoffsetx", "textoffsety", "radiowidth", "radioheight", "radioposx", "radioposy", "textwidth", "border"}
Public doc As New XmlDocument()
Public multiplyFactor As Double = 1.5
Public Filenames As String() = {}
Public SafeFilenames As String() = {}
Public elementlist As XmlNodeList ' must be seperate for all ??
Public TempLetter As String
Public ElementCounter As String
Private Sub Filechooser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ConversionDropDown.Items.Add("720p --> 1080p")
ConversionDropDown.Items.Add("No Change")
ConversionDropDown.SelectedIndex = 0
EncodingDropDown.Items.Add("UTF-8")
EncodingDropDown.Items.Add("ANSI")
EncodingDropDown.SelectedIndex = 0
OutputLog.AppendText("Program started" & vbCrLf)
End Sub
Private Sub ChooseButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChooseButton.Click
OpenFileDialog.Title = "Choose XML file"
OpenFileDialog.Filter = "XML Files|*.xml"
Dim DidWork As Integer = OpenFileDialog.ShowDialog()
If DidWork = DialogResult.Cancel Then
Else
OutputButton.Visible = True
Filenames = OpenFileDialog.FileNames
SafeFilenames = OpenFileDialog.SafeFileNames
If Filenames.Length = 1 Then
OutputLog.AppendText("XML File chosen: " + SafeFilenames(0) & vbCrLf)
xmlname.Text = SafeFilenames(0)
Else
OutputLog.AppendText("Amount Of Files Chosen: " + Filenames.Length.ToString & vbCrLf)
For i = 0 To Filenames.Length - 1
OutputLog.AppendText(SafeFilenames(i) & vbCrLf)
Next i
xmlname.Text = Filenames.Length.ToString + " Files chosen"
End If
If strOutputFolder <> "" Then
ConvertButton.Enabled = True
End If
End If
End Sub
Sub changeElements(ByVal tag As String, ByVal counter As Integer)
OutputLog.AppendText("Changing " + tag + " values..." & vbCrLf)
elementlist = doc.GetElementsByTagName(tag)
For i = 0 To elementlist.Count - 1
Dim number As Integer
If Int32.TryParse(elementlist(i).InnerXml, number) Then
elementlist(i).InnerXml = number
OutputLog.AppendText(elementlist(i).InnerXml)
OutputLog.AppendText(" => ")
elementlist(i).InnerXml = Math.Round(elementlist(i).InnerXml * multiplyFactor)
OutputLog.AppendText(elementlist(i).InnerXml & vbCrLf)
Else
OutputLog.AppendText("Attempted conversion of " + elementlist(i).InnerXml + " failed." & vbCrLf)
If elementlist(i).InnerXml.Length > 0 Then
' TempLetter = elementlist(i).InnerXml.ToString.Substring(0, 1)
elementlist(i).InnerXml = elementlist(i).InnerXml.ToString.Substring(0, elementlist(i).InnerXml.Length - 1)
OutputLog.AppendText("Removed last letter... " & vbCrLf)
OutputLog.AppendText(elementlist(i).InnerXml & vbCrLf)
If Int32.TryParse(elementlist(i).InnerXml, number) Then
OutputLog.AppendText("success " & vbCrLf)
elementlist(i).InnerXml = Math.Round(elementlist(i).InnerXml * multiplyFactor)
OutputLog.AppendText(elementlist(i).InnerXml & vbCrLf)
End If
End If
End If
Next i
End Sub
Public Sub ConvertButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ConvertButton.Click
Try
' Create an XML declaration.
Dim xmldecl As XmlDeclaration
xmldecl = doc.CreateXmlDeclaration("1.0", Nothing, Nothing)
Select Case EncodingDropDown.SelectedIndex
Case 0
xmldecl.Encoding = "UTF-8"
Case 1
xmldecl.Encoding = "ISO-8859-1"
End Select
xmldecl.Standalone = "yes"
Select Case ConversionDropDown.SelectedIndex
Case 0
multiplyFactor = 1.5
OutputLog.AppendText("converting 720 ==> 1080: Factor 1.5" & vbCrLf)
Case 1
multiplyFactor = 1
OutputLog.AppendText("only converting Encoding / adding Headers" & vbCrLf)
End Select
ElementCounter = 0
For j = 0 To Filenames.Length - 1
OutputLog.AppendText("Processing " + SafeFilenames(j) & vbCrLf)
'Create the XmlDocument.
doc.Load(Filenames(j))
If HeaderOption.Checked Then
Dim root As XmlElement = doc.DocumentElement
doc.InsertBefore(xmldecl, root)
End If
If multiplyFactor <> 1 Then
For i = 0 To StrArray.Length - 1
changeElements(StrArray(i), j)
Next i
End If
' If EncodingDropDown.SelectedIndex = 0 Then
Dim wrtr As XmlTextWriter = Nothing
Select Case EncodingDropDown.SelectedIndex
Case 0
wrtr = New XmlTextWriter(strOutputFolder + "\" + SafeFilenames(j), Encoding.UTF8)
Case 1
wrtr = New XmlTextWriter(strOutputFolder + "\" + SafeFilenames(j), Encoding.ASCII)
End Select
wrtr.Formatting = Formatting.Indented
doc.WriteTo(wrtr)
wrtr.Close()
OutputLog.AppendText(SafeFilenames(j) + " created successfully" & vbCrLf)
ElementCounter = ElementCounter + 1
Next j
Catch xmlex As XmlException ' Handle the Xml Exceptions here.
Console.WriteLine("{0}", xmlex.Message)
Catch ex As Exception ' Handle the generic Exceptions here.
Console.WriteLine("{0}", ex.Message)
End Try
OutputLog.AppendText("All Files converted" & vbCrLf)
MsgBox(ElementCounter + " XML Files converted." & vbCrLf & "Please adjust the remaining tags by hand")
ReDim Filenames(0)
ReDim SafeFilenames(0)
xmlname.Text = ""
ConvertButton.Enabled = False
End Sub
Private Sub OutputButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OutputButton.Click
Do
FolderBrowserDialog.Description = "Choose Output Folder"
Dim DidWork As Integer = FolderBrowserDialog.ShowDialog()
If DidWork = DialogResult.Cancel Then
Else
strOutputFolder = FolderBrowserDialog.SelectedPath
If Filenames(0) <> "" Then
ConvertButton.Enabled = True
End If
OutputLabel.Text = strOutputFolder + "\"
OutputLog.AppendText("Output Folder chosen:" & vbCrLf)
OutputLog.AppendText(strOutputFolder & vbCrLf)
End If
If (strOutputFolder + "\" + SafeFilenames(0) = Filenames(0)) Then
MsgBox("You´ve chosen the soure directory. please change the output path.")
End If
Loop While (strOutputFolder + "\" + SafeFilenames(0) = Filenames(0))
End Sub
End Class
If someone wants to have the project files, just ask.
|