split the string data and build a xml string by using linq to xml format in c# -


trying split string data , build xml format using linq xml,but facing difficulities generate xml string

mystring = {1:abcd}{2:efgh}{3:/r/n:12:mmm/r/n:65:nnn} 

required output :

<message> <block1> <value>abcd</value> </block1> <block2> <value>efgh</value> </block2> <block3> <tag>12</tag> <value>mmm</value> <tag>65</tag> <value>nnn</value> </block3> </message> 

kindly advice on above same

mystring = {1:abcd}{2:efgh}{3:/r/n:12:mmm/r/n:65:nnn} 
  • first use regex matching patterns of brackets.

1:abcd 2:efgh 3:/r/n:12:mmm/r/n:65:nnn

  • then resulting strings contain strings build xml. may want replace /r/n empty space in "3:/r/n:12:mmm/r/n:65:nnn".replace("/r/n", ""). call .split(':') turn array.

  • from there going have develop logic parse string array nodes. appears if value can int.tryparse(string, out int value) goes tag element otherwise value element.

  • and of course skip empty array elements. can in split split(':', stringsplitoptions.removeemptyentries) if ok not seeing them in resulting array.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -