So this explain why i spent 4 hours trying to code a a vast array of different XML Readers and nothing worked... I would post my codes here, but as i wrote, i tried about 6 or 7 methods before, so i gave up about XML editing and started to work in simple text reader...
My text here will be BIG, so sorry, i', trying to provide enough information...
This XML is a file From a Game, those files has about 1500 lines each, and game has about 200 different xml ones.
I normally edit with Notepad++ about 20 lines for file to make some changes on game, but it's very easy to make a mistake and crash game, my ideia is to make a vb.net editor, cappable to read specific lines and be able to edit it safely.
I found a workaround, if you took a look in line:
<field name="disEntityId" type="Int64">19832</field>
My code looks for specific string in a line, for example
"disEntityId"
, then read values betweeen
"">" and "</f"
...
But i had two problems here: I can't make a code to write new value and work properly, and also, there are some lines that has the very same name, and i need to edit, like:
<object name="RangeMultiplierHardcore">
<object name="RangeMultiplierDifficulty">
<object name="RangeMultiplier">
<!--THIS LINE--> <field name="fStartMultiplier" type="Float32">1</field>
</object>
</object>
</object>
<object name="RangeMultiplierCasual">
<object name="RangeMultiplierDifficulty">
<object name="RangeMultiplier">
<!--AND THIS LINE--> <field name="fStartMultiplier" type="Float32">2</field>
</object>
</object>
</object>
As you can see, i need to edit the line where the following string is:
"fStartMultiplier"
, but this string is shown 2 times under different "Object Names" (RangeMultiplierCasual and Hardcore).
The full XML file is here:
Microsoft OneDrive[
^]
The code i worked to find the Word in line then show it's value is:
Private Sub Proccess()
Textbox1.Text = (StringBetweenChars(FindInLine(XmlFile, """disEntityId""")))
End Sub
Public Function StringBetweenChars(ByVal fullText) As String
Dim start As String = Chr(34) + Chr(62)
Dim ending As String = "</f"
Dim x, j As Integer
x = fullText.IndexOf(start) + 2
j = fullText.IndexOf(ending)
If (j <> -1) Then
Return fullText.Substring(x, j - x)
Else
Return fullText.Substring(x, fullText.Length - x)
End If
End Function
Private Function FindInLine(PathXml As String, Word As String) As String
Using reader As New StreamReader(PathXml)
While Not reader.EndOfStream
Dim line As String = reader.ReadLine()
If line.Contains(Word) Then
FindInLine = line
Exit While
End If
End While
End Using
If Word = "" Then Word = "Não Encontrado!"
End Function
Thanks!