John Darby
asked on
Extract blog content from XML file
Have an XML file which is an export of my wife's WordPress blog. I need to export the blog content. I am attaching the XML file, itself. I have never used XPATH and am willing to learn, but unsure how to proceed. Each blog entry is under <content:encoded>. I am not sure how to simply extract the content into a txt/docx format. Appreciate the help!
Thank you!
JohnD
1stepatatimemindbodyspirit.WordPress.xml
Thank you!
JohnD
1stepatatimemindbodyspirit.WordPress.xml
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you, so much!
Welcome John,
The technology I used is XSLT (that is a language designed for XML transformations)
I will post the XSLT here, it is a version 2.0 but maybe you want to experiment with it
Note it is a very quick hack, so this code is not as nice as I would want it to be (not by far), but still it gives you a starting point
The technology I used is XSLT (that is a language designed for XML transformations)
I will post the XSLT here, it is a version 2.0 but maybe you want to experiment with it
Note it is a very quick hack, so this code is not as nice as I would want it to be (not by far), but still it gives you a starting point
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:math="http://www.w3.org/2005/xpath-functions/math"
exclude-result-prefixes="xs math"
version="2.0">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:value-of select="*:rss/*:channel/*:title"/>
<xsl:text> </xsl:text>
<xsl:value-of select="for $i in 1 to string-length(*:rss/*:channel/*:title) return '='" separator=""/>
<xsl:text> </xsl:text>
<xsl:apply-templates select="*:rss/*:channel/*:item"></xsl:apply-templates>
</xsl:template>
<xsl:template match="*:item">
<xsl:text> </xsl:text>
<xsl:text> </xsl:text>
<xsl:value-of select="for $i in 1 to string-length(*:title) return '-'" separator=""/>
<xsl:text> </xsl:text>
<xsl:value-of select="*:title"/>
<xsl:text> </xsl:text>
<xsl:value-of select="for $i in 1 to string-length(*:title) return '-'" separator=""/>
<xsl:text> </xsl:text>
<xsl:value-of select="*:encoded"/>
</xsl:template>
</xsl:stylesheet>
ASKER