I wanted a PHP script to echo an XML-formatted results of a query to a MySQL database table. The script crashed/stopped when i had german umlaut or special character like ä,ö,ü,ß in a text column in the database
How-I-fixed-it:
There where a couple of steps required for me to make the special characters come through to the client browser.
1. Set the collation of the database table and the char columns to charset "utf8_general_ci"
2. In the PHP-code, force the DOMDocument to be UTF-8: $dom = new DOMDocument("1.0","UTF-8");
3. Set the database queries to be UTF-8: $names=mysql_query('set names utf8');
4. Set the charset of the mysql_connection to be UTF-8: mysqli_set_charset($connection, 'utf8');
5. Tell the client browser that the data is UTF-8 encoded: header('Content-Type: text/xml; charset=utf-8');
Maybe not all steps are really necessary, but once it worked for me, i left it that way :-)
I found some help here:
http://www.winfuture-forum.de/index.php?showtopic=193063
http://php.net/manual/de/domdocument.savexml.php
http://www.mysqltutorial.org/mysql-collation/
This blog is about problems i encountered in everyday life and how i fixed them or worked around them. Sometimes i also just post things to let people out there know about something i think it might be of interest for others than me....
Showing posts with label XML. Show all posts
Showing posts with label XML. Show all posts
Tuesday, April 28, 2015
Tuesday, February 17, 2015
log4net AdoNetAppender stops logging / does not recover if database connection is lost / database is down, ReconnectOnError
I use the Apache log4net AdoNetAppender to log information from my application into a SQL database. In case, the network connection to the database is lost or the database is down for some reason, the AdoNetAppender quits logging (forever) to the database and does not recover even if the database is online again.
How-I-fixed-it:
I found the right hints here:
https://www.mail-archive.com/log4net-user@logging.apache.org/msg04655.html
http://logging.apache.org/log4net/release/sdk/log4net.Appender.AdoNetAppender.ReconnectOnError.html
Add the tag:
to the log4net XML config file:
Keep in mind, that it then tries to reconnect to the database until the connect times out. This blocks the thread of the application!
You can add:
Connect Timeout=1 to the connectionString property to Limit the blocking to 1 second:
How-I-fixed-it:
I found the right hints here:
https://www.mail-archive.com/log4net-user@logging.apache.org/msg04655.html
http://logging.apache.org/log4net/release/sdk/log4net.Appender.AdoNetAppender.ReconnectOnError.html
Add the tag:
to the log4net XML config file:
Keep in mind, that it then tries to reconnect to the database until the connect times out. This blocks the thread of the application!
You can add:
Connect Timeout=1 to the connectionString property to Limit the blocking to 1 second:
Thursday, February 18, 2010
Post XML/HTML Sourcecode inside a Blog
If you need to post HTML / XML inside a Blog-Post, see this great Link:
http://cherupally.blogspot.com/2009/05/how-to-post-html-code-in-blogspot.html
http://cherupally.blogspot.com/2009/05/how-to-post-html-code-in-blogspot.html
Export parts of Firefox bookmarks to HTML or Trac
After searching around on the web for a while, i decided to write my own little conversion tool to export only parts of my firefox bookmarks, e.g. subfolders, to a HTML-File or in TRAC format.
Here's how i did it:
I added the OPML Addon to my firefox: https://addons.mozilla.org/de/firefox/addon/2625
I exported my bookmarks to an OPML-File, which is just XML.
Next i create a little XSL-Stylesheet that converts the OPML to the desired format.
To convert OPML to TRAC links the XSLT looks like this (OPML2TRAC.xsl):
To convert OPML to HTML links the XSLT looks like this (OPML2HTML.xsl):
Replace the "PlaceTheNameOfYourSubfolderHere" value with the name of the Subfolder of your firefox bookmarks.
In the head of the OPML-File insert the reference to the XSL-File:
Open the OPML in Firefox or Internet Explorer now. You should then see the converted result.
You can also use a XSLT-Processor, e.g. MSXSL to do the conversion.
Here's how i did it:
I added the OPML Addon to my firefox: https://addons.mozilla.org/de/firefox/addon/2625
I exported my bookmarks to an OPML-File, which is just XML.
Next i create a little XSL-Stylesheet that converts the OPML to the desired format.
To convert OPML to TRAC links the XSLT looks like this (OPML2TRAC.xsl):
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="utf-16" media-type="text/plain" omit-xml-declaration="yes" indent="no"/>
<xsl:variable name="exportRootFolderName">PlaceTheNameOfYourSubfolderHere</xsl:variable>
<xsl:template match="/">
<xsl:for-each select="//outline[@text=$exportRootFolderName]">
<xsl:call-template name="outlineConvert"></xsl:call-template>
</xsl:for-each>
</xsl:template>
<xsl:template name="outlineConvert">
<xsl:for-each select="outline[@url != '']">
<xsl:sort select="@text" />[<xsl:value-of select="./@url" disable-output-escaping="yes"/><xsl:text> </xsl:text><xsl:value-of select="./@text"/>]<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
To convert OPML to HTML links the XSLT looks like this (OPML2HTML.xsl):
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="utf-16" media-type="text/html" omit-xml-declaration="yes" indent="no"/>
<xsl:variable name="exportRootFolderName">PlaceTheNameOfYourSubfolderHere</xsl:variable>
<xsl:template match="/">
<xsl:for-each select="//outline[@text=$exportRootFolderName]">
<xsl:call-template name="outlineConvert"></xsl:call-template>
</xsl:for-each>
</xsl:template>
<xsl:template name="outlineConvert">
<html>
<body>
<h2>My Bookmarks</h2>
<table border="1">
<xsl:for-each select="outline[@url != '']">
<xsl:sort select="@text" />
<tr>
<td>
<a>
<xsl:attribute name="href">
<xsl:value-of select="./@url"/>
</xsl:attribute>
<xsl:value-of select="./@text"/>
</a>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Replace the "PlaceTheNameOfYourSubfolderHere" value with the name of the Subfolder of your firefox bookmarks.
In the head of the OPML-File insert the reference to the XSL-File:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="opml2trac.xsl"?>
<opml version="1.0">
... Rest of the OPML file ...
Open the OPML in Firefox or Internet Explorer now. You should then see the converted result.
You can also use a XSLT-Processor, e.g. MSXSL to do the conversion.
Subscribe to:
Posts (Atom)