/README.C-LANG

http://github.com/fizx/parsley · Unknown · 92 lines · 63 code · 29 blank · 0 comment · 0 complexity · cfcbcc1d68e5102c3375e8fc36c62299 MD5 · raw file

  1. To use parsley from C, the following functions are available from parsley.h. In
  2. addition, there is a function to convert xml documents of the type returned by
  3. parsley into json.
  4. You will also need passing familiarity with libxml2 and json-c to print, manipulate, and free some of the generated objects.
  5. - http://svn.metaparadigm.com/svn/json-c/trunk
  6. - http://xmlsoft.org/
  7. From parsley.h
  8. =============
  9. parsedParsleyPtr -- a struct that contains the following elements:
  10. - xmlDocPtr xml -- the output of a parselet document parse, as a libxml2 document
  11. - char *error -- an error message, or NULL if no error
  12. - compiled_parsley *parsley -- reference to the parsley that did the parsing
  13. parsleyPtr parsley_compile(char* parsley, char* incl)
  14. Arguments:
  15. - char* parsley -- a string of parsley to compile.
  16. - char* incl -- arbitrary XSLT to inject directly into the stylesheet,
  17. outside any templates.
  18. Returns: A structure that you can pass to parsley_parse_* to do the actual
  19. parsing. This structure contains the compiled XSLT.
  20. Notes: This is *NOT* thread-safe. (Usage of the parselet via parsley_parse_* *IS*
  21. thread-safe, however.)
  22. void parsley_set_user_agent(char *);
  23. Sets the user-agent used by parsley's internal http library.
  24. void parsley_free(parsleyPtr);
  25. Frees the parsleyPtr's memory.
  26. void parsed_parsley_free(parsedParsleyPtr);
  27. Frees the parsedParsleyPtr's memory.
  28. parsedParsleyPtr parsley_parse_file(parsleyPtr parsley, char* file_name, int flags);
  29. Arguments:
  30. - parsleyPtr parsley -- Compiled parsley struct
  31. - char* file_name -- file to parse
  32. - int flags -- a bitmask as follows:
  33. enum {
  34. PARSLEY_OPTIONS_HTML = 1,
  35. PARSLEY_OPTIONS_PRUNE = 2,
  36. PARSLEY_OPTIONS_ALLOW_NET = 4,
  37. PARSLEY_OPTIONS_ALLOW_LOCAL = 8,
  38. PARSLEY_OPTIONS_COLLATE = 16,
  39. PARSLEY_OPTIONS_SGWRAP = 32
  40. };
  41. Returns: A libxml2 document of the extracted data. You need to free this
  42. with xmlFree(). To output, look at the libxml2 documentation for functions
  43. like xmlSaveFormatFile(). If you want json output, look below for xml2json
  44. docs.
  45. parsedParsleyPtr parsley_parse_string(parsleyPtr parsley, char* string, size_t len, char * base_uri, int flags);
  46. Parses the in-memory string/length combination given. See parsley_parse_file
  47. docs.
  48. parsedParsleyPtr parsley_parse_doc(parsleyPtr parsley, xmlDocPtr doc, bool prune);
  49. Uses the parsley parser to parse a libxml2 document.
  50. From xml2json.h
  51. ===============
  52. struct json_object * xml2json(xmlNodePtr);
  53. Converts an xml subtree to json. The xml should be in the format returned
  54. by parsley. Basically, xml attributes get ignored, and if you want an array
  55. like [a,b], use:
  56. <parsley:groups>
  57. <parsley:group>a</parsley:group>
  58. <parsley:group>b</parsley:group>
  59. </parsley:groups>
  60. To get a null-terminated string out, use:
  61. json_object_to_json_string(struct json_object *)
  62. To free (actually, to decrement the reference count), call:
  63. json_object_put(struct json_object *)