Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
92 lines (63 sloc) 2.97 KB
To use parsley from C, the following functions are available from parsley.h. In
addition, there is a function to convert xml documents of the type returned by
parsley into json.
You will also need passing familiarity with libxml2 and json-c to print, manipulate, and free some of the generated objects.
From parsley.h
parsedParsleyPtr -- a struct that contains the following elements:
- xmlDocPtr xml -- the output of a parselet document parse, as a libxml2 document
- char *error -- an error message, or NULL if no error
- compiled_parsley *parsley -- reference to the parsley that did the parsing
parsleyPtr parsley_compile(char* parsley, char* incl)
- char* parsley -- a string of parsley to compile.
- char* incl -- arbitrary XSLT to inject directly into the stylesheet,
outside any templates.
Returns: A structure that you can pass to parsley_parse_* to do the actual
parsing. This structure contains the compiled XSLT.
Notes: This is *NOT* thread-safe. (Usage of the parselet via parsley_parse_* *IS*
thread-safe, however.)
void parsley_set_user_agent(char *);
Sets the user-agent used by parsley's internal http library.
void parsley_free(parsleyPtr);
Frees the parsleyPtr's memory.
void parsed_parsley_free(parsedParsleyPtr);
Frees the parsedParsleyPtr's memory.
parsedParsleyPtr parsley_parse_file(parsleyPtr parsley, char* file_name, int flags);
- parsleyPtr parsley -- Compiled parsley struct
- char* file_name -- file to parse
- int flags -- a bitmask as follows:
enum {
Returns: A libxml2 document of the extracted data. You need to free this
with xmlFree(). To output, look at the libxml2 documentation for functions
like xmlSaveFormatFile(). If you want json output, look below for xml2json
parsedParsleyPtr parsley_parse_string(parsleyPtr parsley, char* string, size_t len, char * base_uri, int flags);
Parses the in-memory string/length combination given. See parsley_parse_file
parsedParsleyPtr parsley_parse_doc(parsleyPtr parsley, xmlDocPtr doc, bool prune);
Uses the parsley parser to parse a libxml2 document.
From xml2json.h
struct json_object * xml2json(xmlNodePtr);
Converts an xml subtree to json. The xml should be in the format returned
by parsley. Basically, xml attributes get ignored, and if you want an array
like [a,b], use:
To get a null-terminated string out, use:
json_object_to_json_string(struct json_object *)
To free (actually, to decrement the reference count), call:
json_object_put(struct json_object *)