2 Copyright (c) 2008 Instituto Nokia de Tecnologia
5 Redistribution and use in source and binary forms, with or without modification,
6 are permitted provided that the following conditions are met:
8 * Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright notice,
11 this list of conditions and the following disclaimer in the documentation
12 and/or other materials provided with the distribution.
13 * Neither the name of the INdT nor the names of its contributors
14 may be used to endorse or promote products derived from this software
15 without specific prior written permission.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 POSSIBILITY OF SUCH DAMAGE.
29 #ifndef __GCAL_XML_AUX__
30 #define __GCAL_XML_AUX__
34 * @author Adenilson Cavalcanti da Silva <adenilson.silva@indt.org.br>
35 * @date Fri Mar 28 14:31:21 2008
37 * @brief Auxiliary code to parse XML using XPath, iIt depends on libxml.
39 * I started with 'xpath1.c' libxml example written by Aleksey Sanin
40 * (which uses MIT license).
41 * In the end my code turn out to be rather different from him, but
42 * I decided to keep the same function names.
46 #include <libxml/tree.h>
47 #include <libxml/parser.h>
48 #include <libxml/xpath.h>
49 #include <libxml/xpathInternals.h>
50 #include <libxml/xmlwriter.h>
52 /** Atom URL/URI (ps: Its shared with \ref gcal_parser) */
53 static const char atom_href
[] = "http://www.w3.org/2005/Atom";
54 static const char atom_ns
[] = "atom";
56 /** Google data URL/URI */
57 static const char gd_href
[] = "http://schemas.google.com/g/2005";
58 static const char gd_ns
[] = "gd";
60 /** Google group membership URL/URI */
61 static const char gContact_href
[] = "http://schemas.google.com/contact/2008";
62 static const char gContact_ns
[] = "gContact";
64 /** Opensearch URL/URI */
65 static const char open_search_href
[] = "http://a9.com/-/spec/opensearch/1.1/";
66 static const char open_search_ns
[] = "openSearch";
70 /** Call this function to register a namespace within a xmlXPathContext.
73 * @param xpathCtx A pointer to a libxml:xmlXPathContext.
75 * @param name_space Namespace name (e.g. 'gd' for google data). With NULL
76 * it will register gcalendar required namespaces (gd, atom, openSearch).
78 * @param href A URL/URI reference to the namespace. Pass NULL to register
79 * gcalendar namespaces.
81 * @return 0 on success, -1 otherwise.
83 int register_namespaces(xmlXPathContext
*xpathCtx
, const xmlChar
*name_space
,
87 /** Executes a XPath expression within a XML tree document.
90 * @param doc A libxml document pointer.
92 * @param xpathExpr A pointer to a string with the xpath expression
93 * (e.g. '//openSearch:totalResults/text()')
95 * @param xpathCtx Pointer to a xmlXPathContext (which you can configure its
96 * namespaces using \ref register_namespaces). If you wish to use the default
97 * gcalendar namespaces, pass NULL.
99 * @return A pointer to a xmlXPathObject with the result of XPath expression
100 * (you must cleanup its memory using 'xmlXPathFreeObject').
102 xmlXPathObject
* execute_xpath_expression(xmlDoc
*doc
,
103 const xmlChar
* xpathExpr
,
104 xmlXPathContext
*xpathCtx
);
106 /** Allocates resources to create a XML document.
109 * @param writer Pointer to pointer to a libxml TextWriter.
111 * @param buffer Pointer to pointer to a libxml buffer.
113 * @return 0 on sucess, -1 on error.
115 int xmlentry_init_resources(xmlTextWriter
**writer
, xmlBuffer
**buffer
);
118 /** Destroys resources required to create a XML document.
121 * @param writer Pointer to pointer to a libxml TextWriter.
123 * @param buffer Pointer to pointer to a libxml buffer.
125 void xmlentry_destroy_resources(xmlTextWriter
**writer
, xmlBuffer
**buffer
);