PageRenderTime 10ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/README.C-LANG

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