Jump to content

6 posts in this topic

Posted

Hello gang,

 

I am making a Windows Phone app that reads the NYC transit info.    The mta has a data feed: http://mta.info/status/serviceStatus.txt  but the <text? tag is filled with various html tags and symbols.  Sadly enough wrapping this up in <html></html> tags does not allow it to render so I was looking to simply clear it out with string replace (ugly, I know) so I thought I'd look for other ideas here.

 

James

Share this post


Link to post
Share on other sites

Posted

XmlDocument doc = new XmlDocument();
 
doc.Load("http://mta.info/status/serviceStatus.txt");
 
var texts = doc.GetElementsByTagName("text");
 
string innerText = texts[0].InnerText;
 
var t = Regex.Replace(innerText, @"<(.|\n)*?>", "");

It [I]does[/I] render fine in a WebBrowser control if you use control.NavigateToString(node.InnerText).

It's an evil, filthy hack but it works as long as none of the data has "<>" around it.

Share this post


Link to post
Share on other sites

Posted

Really?!   Very interesting.  Thanks.  I will check it out.

The next question is how did you figure this out?  Meaning, how did you know that it would work without some of these characters?

Share this post


Link to post
Share on other sites

Posted

HTML is a subset of SGML like XML. The <text> blocks have to be escaped to be valid XML, but the XmlDocument class reads the & meta tags as if they were what they represent. (e.g.: "<" instead of "&lt;".

Unless they toss in some text inside of <> brackets the text should parse through Regex just fine. You'd just be missing whatever is in the brackets.

 

As for the WebBrowser control, I already knew the NavigateToString() method didn't require a full document. :)

 

You could probably parse the tags themselves and convert the HTML to RTF and shove it in a RichTextBox control instead, too.

Share this post


Link to post
Share on other sites

Posted

Sad to admit that I did not know HTML was a subset of SGML (after ALL of these years) 

 

I can't use the XMLDocument class in a WP8 app, but I can work that out, likely with the XDocument class.  Again, I'm more impressed that you knew that this data would work in this fashion.

 

Have a great evening

Share this post


Link to post
Share on other sites

Posted

XDocument should work just fine. I was going to suggest it but I wasn't sure if it was in Silverlight.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.