Question Saving xml changes

DarkGamerNZ

New member
Joined
Dec 16, 2016
Messages
2
Programming Experience
5-10
This is an example of xml im trying to save changes to, there are other files with the same structure but different entries.
VB.NET:
<?xml version="1.0" encoding="UTF-8"?>

<CHandlingDataMgr>
  <HandlingData>
   <Item type="CHandlingData">
      <handlingName>AIRTUG</handlingName>
      <fMass value="1400.000000" />
      <fInitialDragCoeff value="30.000000" />
      <fPercentSubmerged value="85.000000" />
      <vecCentreOfMassOffset x="0.000000" y="0.000000" z="0.000000" />
      <vecInertiaMultiplier x="1.000000" y="1.000000" z="1.000000" />
      <fDriveBiasFront value="1.000000" />
      <nInitialDriveGears value="1" />
      <fInitialDriveForce value="0.060000" />
      <fDriveInertia value="1.000000" />
      <fClutchChangeRateScaleUpShift value="1.300000" />
      <fClutchChangeRateScaleDownShift value="1.300000" />
      <fInitialDriveMaxFlatVel value="40.000000" />
      <fBrakeForce value="0.300000" />
      <fBrakeBiasFront value="0.450000" />
      <fHandBrakeForce value="0.350000" />
      <fSteeringLock value="30.000000" />
      <fTractionCurveMax value="1.150000" />
      <fTractionCurveMin value="0.950000" />
      <fTractionCurveLateral value="11.000000" />
      <fTractionSpringDeltaMax value="0.100000" />
      <fLowSpeedTractionLossMult value="0.000000" />
      <fCamberStiffnesss value="0.000000" />
      <fTractionBiasFront value="0.450000" />
      <fTractionLossMult value="1.000000" />
      <fSuspensionForce value="4.000000" />
      <fSuspensionCompDamp value="1.500000" />
      <fSuspensionReboundDamp value="1.500000" />
      <fSuspensionUpperLimit value="0.100000" />
      <fSuspensionLowerLimit value="-0.100000" />
      <fSuspensionRaise value="0.000000" />
      <fSuspensionBiasFront value="0.500000" />
      <fAntiRollBarForce value="0.000000" />
      <fAntiRollBarBiasFront value="0.000000" />
      <fRollCentreHeightFront value="0.200000" />
      <fRollCentreHeightRear value="0.200000" />
      <fCollisionDamageMult value="1.000000" />
      <fWeaponDamageMult value="1.000000" />
      <fDeformationDamageMult value="0.800000" />
      <fEngineDamageMult value="1.500000" />
      <fPetrolTankVolume value="0.000000" />
      <fOilVolume value="0.000000" />
      <fSeatOffsetDistX value="0.000000" />
      <fSeatOffsetDistY value="0.000000" />
      <fSeatOffsetDistZ value="0.000000" />
      <nMonetaryValue value="15000" />
      <strModelFlags>440000</strModelFlags>
      <strHandlingFlags>1000</strHandlingFlags>
      <strDamageFlags>20</strDamageFlags>
      <AIHandling>TRUCK</AIHandling>
      <SubHandlingData>
        <Item type="NULL" />
        <Item type="NULL" />
        <Item type="NULL" />
      </SubHandlingData>
    </Item>
    <Item type="CHandlingData">
      <handlingName>ADDER</handlingName>
      <fMass value="1800.000000" />
      <fInitialDragCoeff value="7.800000" />
      <fPercentSubmerged value="85.000000" />
      <vecCentreOfMassOffset x="0.000000" y="0.000000" z="0.000000" />
      <vecInertiaMultiplier x="1.000000" y="1.300000" z="1.500000" />
      <fDriveBiasFront value="0.200000" />
      <nInitialDriveGears value="6" />
      <fInitialDriveForce value="0.320000" />
      <fDriveInertia value="1.000000" />
      <fClutchChangeRateScaleUpShift value="3.000000" />
      <fClutchChangeRateScaleDownShift value="3.000000" />
      <fInitialDriveMaxFlatVel value="160.000000" />
      <fBrakeForce value="1.000000" />
      <fBrakeBiasFront value="0.450000" />
      <fHandBrakeForce value="0.700000" />
      <fSteeringLock value="42.000000" />
      <fTractionCurveMax value="2.500000" />
      <fTractionCurveMin value="2.380000" />
      <fTractionCurveLateral value="22.500000" />
      <fTractionSpringDeltaMax value="0.150000" />
      <fLowSpeedTractionLossMult value="1.500000" />
      <fCamberStiffnesss value="0.000000" />
      <fTractionBiasFront value="0.485000" />
      <fTractionLossMult value="1.000000" />
      <fSuspensionForce value="2.400000" />
      <fSuspensionCompDamp value="1.400000" />
      <fSuspensionReboundDamp value="2.100000" />
      <fSuspensionUpperLimit value="0.120000" />
      <fSuspensionLowerLimit value="-0.100000" />
      <fSuspensionRaise value="0.000000" />
      <fSuspensionBiasFront value="0.500000" />
      <fAntiRollBarForce value="0.900000" />
      <fAntiRollBarBiasFront value="0.600000" />
      <fRollCentreHeightFront value="0.410000" />
      <fRollCentreHeightRear value="0.410000" />
      <fCollisionDamageMult value="0.700000" />
      <fWeaponDamageMult value="1.000000" />
      <fDeformationDamageMult value="0.700000" />
      <fEngineDamageMult value="1.500000" />
      <fPetrolTankVolume value="65.000000" />
      <fOilVolume value="5.000000" />
      <fSeatOffsetDistX value="0.000000" />
      <fSeatOffsetDistY value="0.000000" />
      <fSeatOffsetDistZ value="0.000000" />
      <nMonetaryValue value="80000" />
      <strModelFlags>440010</strModelFlags>
      <strHandlingFlags>0</strHandlingFlags>
      <strDamageFlags>0</strDamageFlags>
      <AIHandling>AVERAGE</AIHandling>
      <SubHandlingData>
        <Item type="CCarHandlingData">
          <fBackEndPopUpCarImpulseMult value="0.075000" />
          <fBackEndPopUpBuildingImpulseMult value="0.030000" />
          <fBackEndPopUpMaxDeltaSpeed value="0.250000" />
        </Item>
        <Item type="NULL" />
        <Item type="NULL" />
      </SubHandlingData>
    </Item>
    <Item type="CHandlingData">
      <handlingName>AIRBUS</handlingName>
      <fMass value="9000.000000" />
      <fInitialDragCoeff value="10.000000" />
      <fPercentSubmerged value="85.000000" />
      <vecCentreOfMassOffset x="0.000000" y="0.000000" z="0.000000" />
      <vecInertiaMultiplier x="1.600000" y="2.000000" z="2.400000" />
      <fDriveBiasFront value="0.500000" />
      <nInitialDriveGears value="4" />
      <fInitialDriveForce value="0.120000" />
      <fDriveInertia value="0.500000" />
      <fClutchChangeRateScaleUpShift value="1.000000" />
      <fClutchChangeRateScaleDownShift value="1.000000" />
      <fInitialDriveMaxFlatVel value="100.000000" />
      <fBrakeForce value="0.250000" />
      <fBrakeBiasFront value="0.650000" />
      <fHandBrakeForce value="0.450000" />
      <fSteeringLock value="35.000000" />
      <fTractionCurveMax value="1.450000" />
      <fTractionCurveMin value="1.350000" />
      <fTractionCurveLateral value="15.000000" />
      <fTractionSpringDeltaMax value="0.130000" />
      <fLowSpeedTractionLossMult value="0.000000" />
      <fCamberStiffnesss value="0.000000" />
      <fTractionBiasFront value="0.475000" />
      <fTractionLossMult value="0.900000" />
      <fSuspensionForce value="2.000000" />
      <fSuspensionCompDamp value="0.900000" />
      <fSuspensionReboundDamp value="1.800000" />
      <fSuspensionUpperLimit value="0.100000" />
      <fSuspensionLowerLimit value="-0.180000" />
      <fSuspensionRaise value="0.000000" />
      <fSuspensionBiasFront value="0.450000" />
      <fAntiRollBarForce value="0.000000" />
      <fAntiRollBarBiasFront value="0.000000" />
      <fRollCentreHeightFront value="0.400000" />
      <fRollCentreHeightRear value="0.400000" />
      <fCollisionDamageMult value="1.000000" />
      <fWeaponDamageMult value="1.000000" />
      <fDeformationDamageMult value="0.800000" />
      <fEngineDamageMult value="1.500000" />
      <fPetrolTankVolume value="120.000000" />
      <fOilVolume value="8.000000" />
      <fSeatOffsetDistX value="0.000000" />
      <fSeatOffsetDistY value="0.000000" />
      <fSeatOffsetDistZ value="0.000000" />
      <nMonetaryValue value="25000" />
      <strModelFlags>20840018</strModelFlags>
      <strHandlingFlags>0</strHandlingFlags>
      <strDamageFlags>20</strDamageFlags>
      <AIHandling>TRUCK</AIHandling>
      <SubHandlingData>
        <Item type="NULL" />
        <Item type="NULL" />
        <Item type="NULL" />
      </SubHandlingData>
    </Item>
    <Item type="CHandlingData">
      <handlingName>AMBULAN</handlingName>
      <fMass value="2500.000000" />
      <fInitialDragCoeff value="6.000000" />
      <fPercentSubmerged value="80.000000" />
      <vecCentreOfMassOffset x="0.000000" y="0.000000" z="0.000000" />
      <vecInertiaMultiplier x="1.000000" y="1.000000" z="1.300000" />
      <fDriveBiasFront value="0.500000" />
      <nInitialDriveGears value="5" />
      <fInitialDriveForce value="0.180000" />
      <fDriveInertia value="1.000000" />
      <fClutchChangeRateScaleUpShift value="1.300000" />
      <fClutchChangeRateScaleDownShift value="1.300000" />
      <fInitialDriveMaxFlatVel value="140.000000" />
      <fBrakeForce value="0.600000" />
      <fBrakeBiasFront value="0.650000" />
      <fHandBrakeForce value="0.400000" />
      <fSteeringLock value="35.000000" />
      <fTractionCurveMax value="1.950000" />
      <fTractionCurveMin value="1.700000" />
      <fTractionCurveLateral value="20.000000" />
      <fTractionSpringDeltaMax value="0.150000" />
      <fLowSpeedTractionLossMult value="0.500000" />
      <fCamberStiffnesss value="0.000000" />
      <fTractionBiasFront value="0.485000" />
      <fTractionLossMult value="1.000000" />
      <fSuspensionForce value="1.400000" />
      <fSuspensionCompDamp value="0.900000" />
      <fSuspensionReboundDamp value="1.300000" />
      <fSuspensionUpperLimit value="0.200000" />
      <fSuspensionLowerLimit value="-0.250000" />
      <fSuspensionRaise value="0.000000" />
      <fSuspensionBiasFront value="0.500000" />
      <fAntiRollBarForce value="0.650000" />
      <fAntiRollBarBiasFront value="0.510000" />
      <fRollCentreHeightFront value="0.300000" />
      <fRollCentreHeightRear value="0.300000" />
      <fCollisionDamageMult value="1.000000" />
      <fWeaponDamageMult value="1.000000" />
      <fDeformationDamageMult value="0.800000" />
      <fEngineDamageMult value="1.500000" />
      <fPetrolTankVolume value="70.000000" />
      <fOilVolume value="8.000000" />
      <fSeatOffsetDistX value="0.000000" />
      <fSeatOffsetDistY value="0.000000" />
      <fSeatOffsetDistZ value="0.000000" />
      <nMonetaryValue value="40000" />
      <strModelFlags>440018</strModelFlags>
      <strHandlingFlags>0</strHandlingFlags>
      <strDamageFlags>0</strDamageFlags>
      <AIHandling>AVERAGE</AIHandling>
      <SubHandlingData>
        <Item type="NULL" />
        <Item type="NULL" />
        <Item type="NULL" />
      </SubHandlingData>
    </Item>
  </HandlingData>
</CHandlingDataMgr>

And this is the code im using to save the changes.
VB.NET:
    Private Sub SaveFile(ByVal FileLocation As String, ByVal SelectedVehicle As Vehicle)
        Dim Handling_Xml As New XmlDocument()
        Handling_Xml.Load(FileLocation)
        Dim VNode As XmlNode = Handling_Xml.SelectSingleNode(String.Format("//CHandlingDataMgr/HandlingData/Item/handlingName", SelectedVehicle.VID))
        If VNode Is Nothing Then
            MsgBox("XmlNode equal to none!")
        Else
            VNode.InnerText = tbhandlingName.Text
            Handling_Xml.Save(FileLocation)
            Redisplay(FileLocation)
        End If
    End Sub

I plan to loop through all of the nodes inside the item nodes and update them with new strings but i can only seem to do it for the first item node and only the handlingName node. I need to change the attributes as well. Also "SelectedVehicle.VID" is an integer containing the item node number. Can anyone help me please? Ive searched the internet for days and can not find anything to help in my case. Also i must add while im not new to vb.net ive never done anything with xml but in this case im making changes to a file that already exists and can not be done any other way.
 

DarkGamerNZ

New member
Joined
Dec 16, 2016
Messages
2
Programming Experience
5-10
Problem solved! After trying a few extra things before giving up this is my example code that worked.
VB.NET:
[COLOR=#141414][FONT=Consolas]    Private Sub SaveFile(ByVal FileLocation As String, ByVal SelectedVehicle As Vehicle)[/FONT][/COLOR]
        SetNode(FileLocation, SelectedVehicle, "//CHandlingDataMgr/HandlingData/Item/handlingName", tbhandlingName.Text, False, Nothing)
        SetNode(FileLocation, SelectedVehicle, "//CHandlingDataMgr/HandlingData/Item/fMass", tbfMass.Text, True, 0)
        Redisplay(FileLocation)
    End Sub
    Private Sub SetNode(ByVal FileLocation As String, ByVal SelectedVehicle As Vehicle, ByVal Vstring As String, ByVal NewInnerText As String, ByVal AttSet As Boolean, ByVal Att As Integer)
        Dim Handling_Xml As New XmlDocument()
        Handling_Xml.Load(FileLocation)
        Dim VNode As XmlNodeList = Handling_Xml.SelectNodes(String.Format(Vstring))
        If AttSet = False Then
            VNode.Item(SelectedVehicle.VID).InnerText = NewInnerText
        ElseIf AttSet = True Then
            VNode.Item(SelectedVehicle.VID).Attributes(Att).InnerText = NewInnerText
        End If
        Handling_Xml.Save(FileLocation)
 [COLOR=#141414][FONT=Consolas]    End Sub[/FONT][/COLOR]
 
Top Bottom