Re: [xml] Remove whitespaces from text nodes
- From: Piotr Sipika <piotreks optonline net>
- To: xml gnome org
- Subject: Re: [xml] Remove whitespaces from text nodes
- Date: Tue, 14 Feb 2012 15:26:14 -0500
On 02/14/2012 03:13 PM, Michael Ludwig wrote:
spam spam spam spam free fr schrieb am 14.02.2012 um 10:59 (+0100):
Is there a function which do this work?
Don't know the C API, but in XSLT there's the function normalize-space()
and it does just what you want, so you might want to take a look at the
source of LibXSLT. Or use XSLT directly.
I spent a bit of time looking for the C call today and wasn't able to
find it. In fact, I doubt there is one, since all space is treated by
libxml2 as significant (see [1] and [2]).
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="text()" priority="2">
<xsl:copy-of select="normalize-space()"/>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
The XSLT solution suggested is the best way in lieu of actually
normalizing the space in C - the choice is yours.
As a side-note, I thought one could get, at least partially, to
eliminating extra white-space using the XML_PARSE_NOBLANKS (as suggested
by Daniel in [1]), but the functionality behind the option seems to have
been modified. I recall being able to remove empty nodes (<node/>) from
the document being parsed using that option -- that is no longer the case.
All the best,
P
1 - http://mail.gnome.org/archives/xml/2004-April/msg00244.html
2 - http://xmlsoft.org/FAQ.html#Developer (see point 3)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]