Parsing iCalendar data with XPath/XSLT
I am working with a XML driven CMS, and before I run off and either write or implement a module that parses the iCal format, I was wondering if there was any way to parse it using ju开发者_运维知识库st XSLT or ideally just an XPath expression, as this is a built in function of the CMS.
Well, your initial problem would be that it's not an XML format. iCalendar files are tagged text:
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
DTSTART:19970714T170000Z
DTEND:19970715T035959Z
SUMMARY;LANGUAGE="en_US":Bastille Day Party
END:VEVENT
END:VCALENDAR
So, parsing that with XPath and XSLT could be challenging. However, there is an XML representation of iCalendar. You can find information about in the xCal Basic spec. The example above (from that spec) looks like:
<?xml version="1.0" TODO_NAMESPACE="foo"?>
<iCalendar xmlns:xCal="urn:ietf:params:xml:ns:xcal">
<vcalendar>
<version>2.0</version>
<prodid>-//hacksw/handcal//NONSGML v1.0//EN</prodid>
<vevent>
<dtstart>19970714T170000Z</dtstart>
<dtendt>19970715T035959Z</dtend>
<summary xml:lang="en_US">Bastille Day Party</summary>
</vevent>
</vcalendar>
</iCalendar>
(I copied from the draft, hence the odd namespace). There's more information on the OASIS Coverpages site and on the CalConnect blog (that's the most up to date).
If you can convert from one to the other, then yes, you could parse it using XPath statements. If not, then you can parse the text. I'm not actually aware of any implementations I'm afraid.
精彩评论