Search code examples
xmlfileconverterstxt2tags

what is better .txt or .xml


I have a question, is it better to read char by char from txt file and make changes. Or it is better to convert txt file to xml, and then to make changes in the file? I have txt file:

 Record: 1
 {
      choice = mobileToMobile:{
      subscriberServicesIndicator = 09,
      callIdentificationNumber = 70 CD BE,
      recordSequenceNumber = 40 63 0F,
      typeOfCallingSubscriber = 01,
      callingPartyNumber = 41 27 27 19 66 91, -> needs to be changed to 41 72 72 91 66 19
      calledPartyNumber = 31 27 37 72 73 10,  -> needs to be changed to 31 72 73 27 37 10
      disconnectingParty = callingPartyRelease,
      dateForStartofCharging = 14 0C 01 1F,  -> change from hexadecimal to decimal number
      timeForStartofCharging = 0A 35 00,     -> ...
      timeForStopofCharging = 0A 38 1D,      ->
      chargeableDuration = 00 03 1E,
      interruptionTime = 00 00 00,
      timeFromRegisterSeizureToStartOfCharging = 00 00 07,
      calledSubscriberInitialServingCellID = 02 06 33,
      originForCharging = 00,
      }
  }
Record: 2
{
...... so on
}

Solution

  • If you do your own thing char by char, you might find that your code isn't optimised and will chow resources like crazy. So in that regard, I would say stay away, unless you really know what you are doing.

    With XML there are a bunch of tools (for example XPath) at your disposal to query and update the values. These tools will probably be highly optimised and thus you can use it without worrying about resources for the best possible performance,

    Just a side note. The text you provided looks a lot like JSON and that might be a third option to use.