-
Notifications
You must be signed in to change notification settings - Fork 38
/
README.C-LANG
92 lines (63 loc) · 2.97 KB
/
README.C-LANG
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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 *)