Removing data with tags from a vector


  1. abc<-""welcome <span class="r"><a href="abc">abc</a></span> Have fun!""
  2.        
  3. abc<-"welcome Have fun"
  4.        
  5. > gsub("(<[^>]*>)","",abc)
  6.        
  7. abc <- "welcome <span class="r"><a href="abc">abc</a></span> Have fun!"
  8. library(XML)
  9. #doc <- htmlParse(abc, asText=TRUE)
  10. doc <- htmlTreeParse(abc, asText=TRUE)
  11. xmlValue( xmlRoot(doc) )
  12.        
  13. f <- function(x) if(xmlName(x) == "span") xmlTextNode(" ") else x
  14. d <- xmlDOMApply( xmlRoot(doc), f )
  15. xmlValue(d)


Learn More :