/README.C-LANG
http://github.com/fizx/parsley · Unknown · 92 lines · 63 code · 29 blank · 0 comment · 0 complexity · cfcbcc1d68e5102c3375e8fc36c62299 MD5 · raw file
- 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.
- - http://svn.metaparadigm.com/svn/json-c/trunk
- - http://xmlsoft.org/
- 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)
- Arguments:
- - 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);
- Arguments:
- - parsleyPtr parsley -- Compiled parsley struct
- - char* file_name -- file to parse
- - int flags -- a bitmask as follows:
- enum {
- PARSLEY_OPTIONS_HTML = 1,
- PARSLEY_OPTIONS_PRUNE = 2,
- PARSLEY_OPTIONS_ALLOW_NET = 4,
- PARSLEY_OPTIONS_ALLOW_LOCAL = 8,
- PARSLEY_OPTIONS_COLLATE = 16,
- PARSLEY_OPTIONS_SGWRAP = 32
- };
-
- 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
- docs.
- 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
- docs.
-
- 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:
-
- <parsley:groups>
- <parsley:group>a</parsley:group>
- <parsley:group>b</parsley:group>
- </parsley:groups>
-
- 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 *)