[erlang-questions] How to extract string between XML tags

lloyd@REDACTED lloyd@REDACTED
Tue Sep 25 23:56:01 CEST 2018


Hello,

By now I should know how to do this. But I've fumbled for more time than I have to find an elegant solution.

Can anyone show a better way?

Example string: "<th>Firstname</th>"  % NOTE: could be any valid tag

My kludge:

extract_text(TaggedText) ->
  Split = re:split(TaggedText, "<"),
  Split2 = lists:nth(2, Split),
  Split3 = binary_to_list(Split2),
  Split4 = re:split(Split3, ">"),
  Split5 = lists:nth(2, Split4),
  binary_to_list(Split5).

Surely there's a better way.

Many thanks,

LRP

*********************************************
My books:

THE GOSPEL OF ASHES
http://thegospelofashes.com

Strength is not enough. Do they have the courage 
and the cunning? Can they survive long enough to 
save the lives of millions?  

FREEIN' PANCHO
http://freeinpancho.com

A community of misfits help a troubled boy find his way 

AYA TAKEO
http://ayatakeo.com

Star-crossed love, war and power in an alternative 
universe

Available through Amazon or by request from your 
favorite bookstore


**********************************************




More information about the erlang-questions mailing list