‘Code’ Category

 

How to Hide Android WebView Highlight Border (or change it’s color)

Here's one that had me at a loss for a long time that I just figured out. You can easily remove the highlight border (the border that comes up when an element is focused) or change it's color in a WebView with CSS! The WebKit-specific property "-webkit-tap-highlight-color" is what you're looking for.

The following line will disable it on a page completely:

1
2
3
* {
	-webkit-tap-highlight-color: rgba(0, 0, 0, 0);	
}

rgba() is just like rgb(), but it takes a 4th parameter for opacity. It's my belief that this would probably work for iPhone WebView's as well, since both Chrome and Safari are based off of WebKit.

 
 
 

PHP RSS Parser – RSS Reader Class for PHP

Just had to create a quick RSS parser for PHP and thought I’d post my solution. The implementation and class follows.

1
2
3
4
5
<?php
$rss = new RSSReader('http://news.google.com/?output=rss');
while ($rss -> hasNext())
	print_r($rss -> next());
?>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
class RSSReader {
	var $xml = null;
	var $pos = 0;
	var $count = 0;
 
	function __construct($feed_url) {
		$this -> load_url($feed_url);
	}
 
	function load_url($feed_url) {
		$this -> load_string(file_get_contents($feed_url));
	}
 
	function load_string($feed_string) {
		$this -> xml = simplexml_load_string(str_replace('content:encoded', 'content_encoded', $feed_string));
		$this -> pos = 0;
		$this -> count = count($this -> xml -> channel -> item);
	}
 
	function get_title() {
		return $this -> xml -> channel -> title;
	}
 
	function get_link() {
		return $this -> xml -> channel -> link;
	}
 
	function get_pubdate() {
		return $this -> xml -> channel -> pubdate;
	}
 
	function hasNext() {
		return $this -> count > $this -> pos;
	}
 
	function next() {
		$obj = $this -> xml -> channel -> item[$this -> pos++];
		return array(
			'title' => (string) $obj -> title,
			'link' => (string) $obj -> link,
			'description' => (string) $obj -> description,
			'content' => (string) $obj -> content_encoded,
			'pubDate' => strtotime($obj -> pubDate),
		);
	}
}
?>
 
 
 

How To Convert Large XML Files to CSV

 I usually struggle with convert very large XML files to other formats just because they are in a dynamic format and most programs you find run out of memory before properly parsing them. Well, I'm happy to say, I found a FAST and EASY solution. Of course this will work for small files as well as big files.

You'll want to grab a copy of the msxsl command line utility from Microsoft.

After you've got that, you'll need to setup a XSL file to tell the program how to format your file. If you're unfamiliar with XSL, you can familiarize yourself here.

After you've got your XSL file created, it's a simple command line entry:

1
msxsl xml_file.xml xsl_file.xsl -o output_file.csv

The following is a sample XML and XSL file that I used.

XML File:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<catalog>
	<content>
		<contentid>772500</contentid>
		<createdate>Tue, 20 Jan 2009 16:28:08 CST</createdate>
		<lastupdatedate>Tue, 20 Jan 2009 16:51:01 CST</lastupdatedate>
 
		<description>
		<artist>
			<id>61951</id>
			<name>The Hills Season 1</name>
		</artist>
	</description></content>
	<content>
		<contentid>773000</contentid>
		<createdate>Tue, 20 Jan 2009 16:28:08 CST</createdate>
		<lastupdatedate>Tue, 20 Jan 2009 16:53:54 CST</lastupdatedate>
 
		<description>
		<artist>
			<id>61926</id>
			<name>Hogan Knows Best Season 2</name>
		</artist>
	</description></content>
	<content>
		<contentid>775500</contentid>
		<createdate>Thu, 22 Jan 2009 14:49:12 CST</createdate>
		<lastupdatedate>Thu, 22 Jan 2009 14:51:35 CST</lastupdatedate>
 
		<description>
		<artist>
			<id>62068</id>
			<name>Carlos Mencia 2007</name>
		</artist>
		<category>
			<id>1402</id>
			<name>Comedy Central</name>
		</category>
	</description></content>
</catalog>

XSL File (Creates tab-delimited file)

1
2
3
4
5
6
7
8
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:template match="/">
		<xsl:for-each select="catalog/content">
			<xsl:value-of select="title"/><xsl:text>	</xsl:text><xsl:value-of select="artist/name"/><xsl:text>
</xsl:text>
		</xsl:for-each>
	</xsl:template>
</xsl:stylesheet>
 
 
 

» Recent Comments

  • Diego: When I've said that "is ...
  • Diego: @ Dan I mainly use...
  • Marcus: Can you make a bookmarks...

» Meta