gtksourceview2 1.2.1-x86-mingw32 → 1.2.2-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/1.9/gtksourceview2.so +0 -0
- data/lib/2.0/gtksourceview2.so +0 -0
- metadata +452 -628
- data/lib/1.8/gtksourceview2.so +0 -0
- data/vendor/local/manifest/libxml2-dev_2.7.7-1_win32.mft +0 -267
- data/vendor/local/manifest/libxml2_2.7.7-1_win32.mft +0 -2
- data/vendor/local/share/doc/libxml2-2.7.7/Copyright +0 -27
- data/vendor/local/share/doc/libxml2-2.7.7/examples/testHTML.c +0 -880
- data/vendor/local/share/doc/libxml2-2.7.7/examples/testSAX.c +0 -1198
- data/vendor/local/share/doc/libxml2-2.7.7/examples/testXPath.c +0 -227
- data/vendor/local/share/doc/libxml2-2.7.7/examples/xmllint.c +0 -3722
- data/vendor/local/share/doc/libxml2-2.7.7/html/DOM.gif +0 -0
- data/vendor/local/share/doc/libxml2-2.7.7/html/FAQ.html +0 -282
- data/vendor/local/share/doc/libxml2-2.7.7/html/Libxml2-Logo-180x168.gif +0 -0
- data/vendor/local/share/doc/libxml2-2.7.7/html/Libxml2-Logo-90x34.gif +0 -0
- data/vendor/local/share/doc/libxml2-2.7.7/html/encoding.html +0 -206
- data/vendor/local/share/doc/libxml2-2.7.7/html/examples.xml +0 -751
- data/vendor/local/share/doc/libxml2-2.7.7/html/examples.xsl +0 -174
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/book1.html +0 -13
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/home.png +0 -0
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/index.html +0 -13
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/left.png +0 -0
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-DOCBparser.html +0 -51
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-HTMLparser.html +0 -182
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-HTMLtree.html +0 -73
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-SAX.html +0 -125
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-SAX2.html +0 -128
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-c14n.html +0 -38
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-catalog.html +0 -142
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-chvalid.html +0 -72
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-debugXML.html +0 -120
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-dict.html +0 -49
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-encoding.html +0 -118
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-entities.html +0 -79
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-globals.html +0 -152
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-hash.html +0 -116
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-lib.html +0 -13
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-list.html +0 -120
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-nanoftp.html +0 -92
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-nanohttp.html +0 -65
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-parser.html +0 -555
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-parserInternals.html +0 -319
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-pattern.html +0 -76
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-relaxng.html +0 -162
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-schemasInternals.html +0 -373
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-schematron.html +0 -81
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-threads.html +0 -72
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-tree.html +0 -958
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-uri.html +0 -73
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-valid.html +0 -289
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-xinclude.html +0 -59
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-xlink.html +0 -82
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-xmlIO.html +0 -206
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-xmlautomata.html +0 -85
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-xmlerror.html +0 -862
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-xmlexports.html +0 -20
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-xmlmemory.html +0 -107
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-xmlmodule.html +0 -38
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-xmlreader.html +0 -327
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-xmlregexp.html +0 -143
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-xmlsave.html +0 -59
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-xmlschemas.html +0 -173
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-xmlschemastypes.html +0 -123
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-xmlstring.html +0 -108
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-xmlunicode.html +0 -512
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-xmlversion.html +0 -60
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-xmlwriter.html +0 -258
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-xpath.html +0 -307
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-xpathInternals.html +0 -394
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/libxml-xpointer.html +0 -83
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/right.png +0 -0
- data/vendor/local/share/doc/libxml2-2.7.7/html/html/up.png +0 -0
- data/vendor/local/share/doc/libxml2-2.7.7/html/io1.c +0 -166
- data/vendor/local/share/doc/libxml2-2.7.7/html/io1.res +0 -5
- data/vendor/local/share/doc/libxml2-2.7.7/html/io2.c +0 -58
- data/vendor/local/share/doc/libxml2-2.7.7/html/io2.res +0 -2
- data/vendor/local/share/doc/libxml2-2.7.7/html/libxml.gif +0 -0
- data/vendor/local/share/doc/libxml2-2.7.7/html/parse1.c +0 -56
- data/vendor/local/share/doc/libxml2-2.7.7/html/parse2.c +0 -72
- data/vendor/local/share/doc/libxml2-2.7.7/html/parse3.c +0 -60
- data/vendor/local/share/doc/libxml2-2.7.7/html/parse4.c +0 -143
- data/vendor/local/share/doc/libxml2-2.7.7/html/reader1.c +0 -107
- data/vendor/local/share/doc/libxml2-2.7.7/html/reader1.res +0 -14
- data/vendor/local/share/doc/libxml2-2.7.7/html/reader2.c +0 -122
- data/vendor/local/share/doc/libxml2-2.7.7/html/reader3.c +0 -120
- data/vendor/local/share/doc/libxml2-2.7.7/html/reader3.res +0 -13
- data/vendor/local/share/doc/libxml2-2.7.7/html/reader4.c +0 -122
- data/vendor/local/share/doc/libxml2-2.7.7/html/reader4.res +0 -3
- data/vendor/local/share/doc/libxml2-2.7.7/html/redhat.gif +0 -0
- data/vendor/local/share/doc/libxml2-2.7.7/html/smallfootonly.gif +0 -0
- data/vendor/local/share/doc/libxml2-2.7.7/html/structure.gif +0 -0
- data/vendor/local/share/doc/libxml2-2.7.7/html/test1.xml +0 -1
- data/vendor/local/share/doc/libxml2-2.7.7/html/test2.xml +0 -13
- data/vendor/local/share/doc/libxml2-2.7.7/html/test3.xml +0 -39
- data/vendor/local/share/doc/libxml2-2.7.7/html/testWriter.c +0 -1198
- data/vendor/local/share/doc/libxml2-2.7.7/html/tree1.c +0 -94
- data/vendor/local/share/doc/libxml2-2.7.7/html/tree1.res +0 -4
- data/vendor/local/share/doc/libxml2-2.7.7/html/tree2.c +0 -118
- data/vendor/local/share/doc/libxml2-2.7.7/html/tree2.res +0 -18
- data/vendor/local/share/doc/libxml2-2.7.7/html/tst.xml +0 -7
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/apa.html +0 -8
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/apb.html +0 -14
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/apc.html +0 -82
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/apd.html +0 -76
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/ape.html +0 -78
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/apf.html +0 -67
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/apg.html +0 -75
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/aph.html +0 -76
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/api.html +0 -4
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/ar01s02.html +0 -14
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/ar01s03.html +0 -47
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/ar01s04.html +0 -54
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/ar01s05.html +0 -55
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/ar01s06.html +0 -35
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/ar01s07.html +0 -30
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/ar01s08.html +0 -38
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/ar01s09.html +0 -63
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/images/blank.png +0 -0
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/images/callouts/1.png +0 -0
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/images/callouts/10.png +0 -0
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/images/callouts/2.png +0 -0
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/images/callouts/3.png +0 -0
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/images/callouts/4.png +0 -0
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/images/callouts/5.png +0 -0
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/images/callouts/6.png +0 -0
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/images/callouts/7.png +0 -0
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/images/callouts/8.png +0 -0
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/images/callouts/9.png +0 -0
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/images/caution.png +0 -0
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/images/draft.png +0 -0
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/images/home.png +0 -0
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/images/important.png +0 -0
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/images/next.png +0 -0
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/images/note.png +0 -0
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/images/prev.png +0 -0
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/images/tip.png +0 -0
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/images/toc-blank.png +0 -0
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/images/toc-minus.png +0 -0
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/images/toc-plus.png +0 -0
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/images/up.png +0 -0
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/images/warning.png +0 -0
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/includeaddattribute.c +0 -64
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/includeaddkeyword.c +0 -75
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/includeconvert.c +0 -73
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/includegetattribute.c +0 -72
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/includekeyword.c +0 -79
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/includexpath.c +0 -74
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/index.html +0 -14
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/ix01.html +0 -1
- data/vendor/local/share/doc/libxml2-2.7.7/html/tutorial/xmltutorial.pdf +0 -1336
- data/vendor/local/share/doc/libxml2-2.7.7/html/w3c.png +0 -0
- data/vendor/local/share/doc/libxml2-2.7.7/html/writer.xml +0 -2
- data/vendor/local/share/doc/libxml2-2.7.7/html/xml.html +0 -5344
- data/vendor/local/share/doc/libxml2-2.7.7/html/xpath1.c +0 -250
- data/vendor/local/share/doc/libxml2-2.7.7/html/xpath1.res +0 -5
- data/vendor/local/share/doc/libxml2-2.7.7/html/xpath2.c +0 -190
- data/vendor/local/share/doc/libxml2-2.7.7/html/xpath2.res +0 -30
- data/vendor/local/src/tml/packaging/libxml2_2.7.7-1_win32.log +0 -1244
- data/vendor/local/src/tml/packaging/libxml2_2.7.7-1_win32.sh +0 -66
@@ -1,250 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* section: XPath
|
3
|
-
* synopsis: Evaluate XPath expression and prints result node set.
|
4
|
-
* purpose: Shows how to evaluate XPath expression and register
|
5
|
-
* known namespaces in XPath context.
|
6
|
-
* usage: xpath1 <xml-file> <xpath-expr> [<known-ns-list>]
|
7
|
-
* test: ./xpath1 test3.xml '//child2' > xpath1.tmp ; diff xpath1.tmp xpath1.res ; rm xpath1.tmp
|
8
|
-
* author: Aleksey Sanin
|
9
|
-
* copy: see Copyright for the status of this software.
|
10
|
-
*/
|
11
|
-
#include <stdlib.h>
|
12
|
-
#include <stdio.h>
|
13
|
-
#include <string.h>
|
14
|
-
#include <assert.h>
|
15
|
-
|
16
|
-
#include <libxml/tree.h>
|
17
|
-
#include <libxml/parser.h>
|
18
|
-
#include <libxml/xpath.h>
|
19
|
-
#include <libxml/xpathInternals.h>
|
20
|
-
|
21
|
-
#if defined(LIBXML_XPATH_ENABLED) && defined(LIBXML_SAX1_ENABLED)
|
22
|
-
|
23
|
-
|
24
|
-
static void usage(const char *name);
|
25
|
-
int execute_xpath_expression(const char* filename, const xmlChar* xpathExpr, const xmlChar* nsList);
|
26
|
-
int register_namespaces(xmlXPathContextPtr xpathCtx, const xmlChar* nsList);
|
27
|
-
void print_xpath_nodes(xmlNodeSetPtr nodes, FILE* output);
|
28
|
-
|
29
|
-
int
|
30
|
-
main(int argc, char **argv) {
|
31
|
-
/* Parse command line and process file */
|
32
|
-
if((argc < 3) || (argc > 4)) {
|
33
|
-
fprintf(stderr, "Error: wrong number of arguments.\n");
|
34
|
-
usage(argv[0]);
|
35
|
-
return(-1);
|
36
|
-
}
|
37
|
-
|
38
|
-
/* Init libxml */
|
39
|
-
xmlInitParser();
|
40
|
-
LIBXML_TEST_VERSION
|
41
|
-
|
42
|
-
/* Do the main job */
|
43
|
-
if(execute_xpath_expression(argv[1], BAD_CAST argv[2], (argc > 3) ? BAD_CAST argv[3] : NULL) < 0) {
|
44
|
-
usage(argv[0]);
|
45
|
-
return(-1);
|
46
|
-
}
|
47
|
-
|
48
|
-
/* Shutdown libxml */
|
49
|
-
xmlCleanupParser();
|
50
|
-
|
51
|
-
/*
|
52
|
-
* this is to debug memory for regression tests
|
53
|
-
*/
|
54
|
-
xmlMemoryDump();
|
55
|
-
return 0;
|
56
|
-
}
|
57
|
-
|
58
|
-
/**
|
59
|
-
* usage:
|
60
|
-
* @name: the program name.
|
61
|
-
*
|
62
|
-
* Prints usage information.
|
63
|
-
*/
|
64
|
-
static void
|
65
|
-
usage(const char *name) {
|
66
|
-
assert(name);
|
67
|
-
|
68
|
-
fprintf(stderr, "Usage: %s <xml-file> <xpath-expr> [<known-ns-list>]\n", name);
|
69
|
-
fprintf(stderr, "where <known-ns-list> is a list of known namespaces\n");
|
70
|
-
fprintf(stderr, "in \"<prefix1>=<href1> <prefix2>=href2> ...\" format\n");
|
71
|
-
}
|
72
|
-
|
73
|
-
/**
|
74
|
-
* execute_xpath_expression:
|
75
|
-
* @filename: the input XML filename.
|
76
|
-
* @xpathExpr: the xpath expression for evaluation.
|
77
|
-
* @nsList: the optional list of known namespaces in
|
78
|
-
* "<prefix1>=<href1> <prefix2>=href2> ..." format.
|
79
|
-
*
|
80
|
-
* Parses input XML file, evaluates XPath expression and prints results.
|
81
|
-
*
|
82
|
-
* Returns 0 on success and a negative value otherwise.
|
83
|
-
*/
|
84
|
-
int
|
85
|
-
execute_xpath_expression(const char* filename, const xmlChar* xpathExpr, const xmlChar* nsList) {
|
86
|
-
xmlDocPtr doc;
|
87
|
-
xmlXPathContextPtr xpathCtx;
|
88
|
-
xmlXPathObjectPtr xpathObj;
|
89
|
-
|
90
|
-
assert(filename);
|
91
|
-
assert(xpathExpr);
|
92
|
-
|
93
|
-
/* Load XML document */
|
94
|
-
doc = xmlParseFile(filename);
|
95
|
-
if (doc == NULL) {
|
96
|
-
fprintf(stderr, "Error: unable to parse file \"%s\"\n", filename);
|
97
|
-
return(-1);
|
98
|
-
}
|
99
|
-
|
100
|
-
/* Create xpath evaluation context */
|
101
|
-
xpathCtx = xmlXPathNewContext(doc);
|
102
|
-
if(xpathCtx == NULL) {
|
103
|
-
fprintf(stderr,"Error: unable to create new XPath context\n");
|
104
|
-
xmlFreeDoc(doc);
|
105
|
-
return(-1);
|
106
|
-
}
|
107
|
-
|
108
|
-
/* Register namespaces from list (if any) */
|
109
|
-
if((nsList != NULL) && (register_namespaces(xpathCtx, nsList) < 0)) {
|
110
|
-
fprintf(stderr,"Error: failed to register namespaces list \"%s\"\n", nsList);
|
111
|
-
xmlXPathFreeContext(xpathCtx);
|
112
|
-
xmlFreeDoc(doc);
|
113
|
-
return(-1);
|
114
|
-
}
|
115
|
-
|
116
|
-
/* Evaluate xpath expression */
|
117
|
-
xpathObj = xmlXPathEvalExpression(xpathExpr, xpathCtx);
|
118
|
-
if(xpathObj == NULL) {
|
119
|
-
fprintf(stderr,"Error: unable to evaluate xpath expression \"%s\"\n", xpathExpr);
|
120
|
-
xmlXPathFreeContext(xpathCtx);
|
121
|
-
xmlFreeDoc(doc);
|
122
|
-
return(-1);
|
123
|
-
}
|
124
|
-
|
125
|
-
/* Print results */
|
126
|
-
print_xpath_nodes(xpathObj->nodesetval, stdout);
|
127
|
-
|
128
|
-
/* Cleanup */
|
129
|
-
xmlXPathFreeObject(xpathObj);
|
130
|
-
xmlXPathFreeContext(xpathCtx);
|
131
|
-
xmlFreeDoc(doc);
|
132
|
-
|
133
|
-
return(0);
|
134
|
-
}
|
135
|
-
|
136
|
-
/**
|
137
|
-
* register_namespaces:
|
138
|
-
* @xpathCtx: the pointer to an XPath context.
|
139
|
-
* @nsList: the list of known namespaces in
|
140
|
-
* "<prefix1>=<href1> <prefix2>=href2> ..." format.
|
141
|
-
*
|
142
|
-
* Registers namespaces from @nsList in @xpathCtx.
|
143
|
-
*
|
144
|
-
* Returns 0 on success and a negative value otherwise.
|
145
|
-
*/
|
146
|
-
int
|
147
|
-
register_namespaces(xmlXPathContextPtr xpathCtx, const xmlChar* nsList) {
|
148
|
-
xmlChar* nsListDup;
|
149
|
-
xmlChar* prefix;
|
150
|
-
xmlChar* href;
|
151
|
-
xmlChar* next;
|
152
|
-
|
153
|
-
assert(xpathCtx);
|
154
|
-
assert(nsList);
|
155
|
-
|
156
|
-
nsListDup = xmlStrdup(nsList);
|
157
|
-
if(nsListDup == NULL) {
|
158
|
-
fprintf(stderr, "Error: unable to strdup namespaces list\n");
|
159
|
-
return(-1);
|
160
|
-
}
|
161
|
-
|
162
|
-
next = nsListDup;
|
163
|
-
while(next != NULL) {
|
164
|
-
/* skip spaces */
|
165
|
-
while((*next) == ' ') next++;
|
166
|
-
if((*next) == '\0') break;
|
167
|
-
|
168
|
-
/* find prefix */
|
169
|
-
prefix = next;
|
170
|
-
next = (xmlChar*)xmlStrchr(next, '=');
|
171
|
-
if(next == NULL) {
|
172
|
-
fprintf(stderr,"Error: invalid namespaces list format\n");
|
173
|
-
xmlFree(nsListDup);
|
174
|
-
return(-1);
|
175
|
-
}
|
176
|
-
*(next++) = '\0';
|
177
|
-
|
178
|
-
/* find href */
|
179
|
-
href = next;
|
180
|
-
next = (xmlChar*)xmlStrchr(next, ' ');
|
181
|
-
if(next != NULL) {
|
182
|
-
*(next++) = '\0';
|
183
|
-
}
|
184
|
-
|
185
|
-
/* do register namespace */
|
186
|
-
if(xmlXPathRegisterNs(xpathCtx, prefix, href) != 0) {
|
187
|
-
fprintf(stderr,"Error: unable to register NS with prefix=\"%s\" and href=\"%s\"\n", prefix, href);
|
188
|
-
xmlFree(nsListDup);
|
189
|
-
return(-1);
|
190
|
-
}
|
191
|
-
}
|
192
|
-
|
193
|
-
xmlFree(nsListDup);
|
194
|
-
return(0);
|
195
|
-
}
|
196
|
-
|
197
|
-
/**
|
198
|
-
* print_xpath_nodes:
|
199
|
-
* @nodes: the nodes set.
|
200
|
-
* @output: the output file handle.
|
201
|
-
*
|
202
|
-
* Prints the @nodes content to @output.
|
203
|
-
*/
|
204
|
-
void
|
205
|
-
print_xpath_nodes(xmlNodeSetPtr nodes, FILE* output) {
|
206
|
-
xmlNodePtr cur;
|
207
|
-
int size;
|
208
|
-
int i;
|
209
|
-
|
210
|
-
assert(output);
|
211
|
-
size = (nodes) ? nodes->nodeNr : 0;
|
212
|
-
|
213
|
-
fprintf(output, "Result (%d nodes):\n", size);
|
214
|
-
for(i = 0; i < size; ++i) {
|
215
|
-
assert(nodes->nodeTab[i]);
|
216
|
-
|
217
|
-
if(nodes->nodeTab[i]->type == XML_NAMESPACE_DECL) {
|
218
|
-
xmlNsPtr ns;
|
219
|
-
|
220
|
-
ns = (xmlNsPtr)nodes->nodeTab[i];
|
221
|
-
cur = (xmlNodePtr)ns->next;
|
222
|
-
if(cur->ns) {
|
223
|
-
fprintf(output, "= namespace \"%s\"=\"%s\" for node %s:%s\n",
|
224
|
-
ns->prefix, ns->href, cur->ns->href, cur->name);
|
225
|
-
} else {
|
226
|
-
fprintf(output, "= namespace \"%s\"=\"%s\" for node %s\n",
|
227
|
-
ns->prefix, ns->href, cur->name);
|
228
|
-
}
|
229
|
-
} else if(nodes->nodeTab[i]->type == XML_ELEMENT_NODE) {
|
230
|
-
cur = nodes->nodeTab[i];
|
231
|
-
if(cur->ns) {
|
232
|
-
fprintf(output, "= element node \"%s:%s\"\n",
|
233
|
-
cur->ns->href, cur->name);
|
234
|
-
} else {
|
235
|
-
fprintf(output, "= element node \"%s\"\n",
|
236
|
-
cur->name);
|
237
|
-
}
|
238
|
-
} else {
|
239
|
-
cur = nodes->nodeTab[i];
|
240
|
-
fprintf(output, "= node \"%s\": type %d\n", cur->name, cur->type);
|
241
|
-
}
|
242
|
-
}
|
243
|
-
}
|
244
|
-
|
245
|
-
#else
|
246
|
-
int main(void) {
|
247
|
-
fprintf(stderr, "XPath support not compiled in\n");
|
248
|
-
exit(1);
|
249
|
-
}
|
250
|
-
#endif
|
@@ -1,190 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* section: XPath
|
3
|
-
* synopsis: Load a document, locate subelements with XPath, modify
|
4
|
-
* said elements and save the resulting document.
|
5
|
-
* purpose: Shows how to make a full round-trip from a load/edit/save
|
6
|
-
* usage: xpath2 <xml-file> <xpath-expr> <new-value>
|
7
|
-
* test: xpath2 test3.xml '//discarded' discarded > xpath2.tmp ; diff xpath2.tmp xpath2.res ; rm xpath2.tmp
|
8
|
-
* author: Aleksey Sanin and Daniel Veillard
|
9
|
-
* copy: see Copyright for the status of this software.
|
10
|
-
*/
|
11
|
-
#include <stdlib.h>
|
12
|
-
#include <stdio.h>
|
13
|
-
#include <string.h>
|
14
|
-
#include <assert.h>
|
15
|
-
|
16
|
-
#include <libxml/tree.h>
|
17
|
-
#include <libxml/parser.h>
|
18
|
-
#include <libxml/xpath.h>
|
19
|
-
#include <libxml/xpathInternals.h>
|
20
|
-
|
21
|
-
#if defined(LIBXML_XPATH_ENABLED) && defined(LIBXML_SAX1_ENABLED) && \
|
22
|
-
defined(LIBXML_OUTPUT_ENABLED)
|
23
|
-
|
24
|
-
|
25
|
-
static void usage(const char *name);
|
26
|
-
static int example4(const char *filename, const xmlChar * xpathExpr,
|
27
|
-
const xmlChar * value);
|
28
|
-
static void update_xpath_nodes(xmlNodeSetPtr nodes, const xmlChar * value);
|
29
|
-
|
30
|
-
|
31
|
-
int
|
32
|
-
main(int argc, char **argv) {
|
33
|
-
/* Parse command line and process file */
|
34
|
-
if (argc != 4) {
|
35
|
-
fprintf(stderr, "Error: wrong number of arguments.\n");
|
36
|
-
usage(argv[0]);
|
37
|
-
return(-1);
|
38
|
-
}
|
39
|
-
|
40
|
-
/* Init libxml */
|
41
|
-
xmlInitParser();
|
42
|
-
LIBXML_TEST_VERSION
|
43
|
-
|
44
|
-
/* Do the main job */
|
45
|
-
if (example4(argv[1], BAD_CAST argv[2], BAD_CAST argv[3])) {
|
46
|
-
usage(argv[0]);
|
47
|
-
return(-1);
|
48
|
-
}
|
49
|
-
|
50
|
-
/* Shutdown libxml */
|
51
|
-
xmlCleanupParser();
|
52
|
-
|
53
|
-
/*
|
54
|
-
* this is to debug memory for regression tests
|
55
|
-
*/
|
56
|
-
xmlMemoryDump();
|
57
|
-
return 0;
|
58
|
-
}
|
59
|
-
|
60
|
-
/**
|
61
|
-
* usage:
|
62
|
-
* @name: the program name.
|
63
|
-
*
|
64
|
-
* Prints usage information.
|
65
|
-
*/
|
66
|
-
static void
|
67
|
-
usage(const char *name) {
|
68
|
-
assert(name);
|
69
|
-
|
70
|
-
fprintf(stderr, "Usage: %s <xml-file> <xpath-expr> <value>\n", name);
|
71
|
-
}
|
72
|
-
|
73
|
-
/**
|
74
|
-
* example4:
|
75
|
-
* @filename: the input XML filename.
|
76
|
-
* @xpathExpr: the xpath expression for evaluation.
|
77
|
-
* @value: the new node content.
|
78
|
-
*
|
79
|
-
* Parses input XML file, evaluates XPath expression and update the nodes
|
80
|
-
* then print the result.
|
81
|
-
*
|
82
|
-
* Returns 0 on success and a negative value otherwise.
|
83
|
-
*/
|
84
|
-
static int
|
85
|
-
example4(const char* filename, const xmlChar* xpathExpr, const xmlChar* value) {
|
86
|
-
xmlDocPtr doc;
|
87
|
-
xmlXPathContextPtr xpathCtx;
|
88
|
-
xmlXPathObjectPtr xpathObj;
|
89
|
-
|
90
|
-
assert(filename);
|
91
|
-
assert(xpathExpr);
|
92
|
-
assert(value);
|
93
|
-
|
94
|
-
/* Load XML document */
|
95
|
-
doc = xmlParseFile(filename);
|
96
|
-
if (doc == NULL) {
|
97
|
-
fprintf(stderr, "Error: unable to parse file \"%s\"\n", filename);
|
98
|
-
return(-1);
|
99
|
-
}
|
100
|
-
|
101
|
-
/* Create xpath evaluation context */
|
102
|
-
xpathCtx = xmlXPathNewContext(doc);
|
103
|
-
if(xpathCtx == NULL) {
|
104
|
-
fprintf(stderr,"Error: unable to create new XPath context\n");
|
105
|
-
xmlFreeDoc(doc);
|
106
|
-
return(-1);
|
107
|
-
}
|
108
|
-
|
109
|
-
/* Evaluate xpath expression */
|
110
|
-
xpathObj = xmlXPathEvalExpression(xpathExpr, xpathCtx);
|
111
|
-
if(xpathObj == NULL) {
|
112
|
-
fprintf(stderr,"Error: unable to evaluate xpath expression \"%s\"\n", xpathExpr);
|
113
|
-
xmlXPathFreeContext(xpathCtx);
|
114
|
-
xmlFreeDoc(doc);
|
115
|
-
return(-1);
|
116
|
-
}
|
117
|
-
|
118
|
-
/* update selected nodes */
|
119
|
-
update_xpath_nodes(xpathObj->nodesetval, value);
|
120
|
-
|
121
|
-
|
122
|
-
/* Cleanup of XPath data */
|
123
|
-
xmlXPathFreeObject(xpathObj);
|
124
|
-
xmlXPathFreeContext(xpathCtx);
|
125
|
-
|
126
|
-
/* dump the resulting document */
|
127
|
-
xmlDocDump(stdout, doc);
|
128
|
-
|
129
|
-
|
130
|
-
/* free the document */
|
131
|
-
xmlFreeDoc(doc);
|
132
|
-
|
133
|
-
return(0);
|
134
|
-
}
|
135
|
-
|
136
|
-
/**
|
137
|
-
* update_xpath_nodes:
|
138
|
-
* @nodes: the nodes set.
|
139
|
-
* @value: the new value for the node(s)
|
140
|
-
*
|
141
|
-
* Prints the @nodes content to @output.
|
142
|
-
*/
|
143
|
-
static void
|
144
|
-
update_xpath_nodes(xmlNodeSetPtr nodes, const xmlChar* value) {
|
145
|
-
int size;
|
146
|
-
int i;
|
147
|
-
|
148
|
-
assert(value);
|
149
|
-
size = (nodes) ? nodes->nodeNr : 0;
|
150
|
-
|
151
|
-
/*
|
152
|
-
* NOTE: the nodes are processed in reverse order, i.e. reverse document
|
153
|
-
* order because xmlNodeSetContent can actually free up descendant
|
154
|
-
* of the node and such nodes may have been selected too ! Handling
|
155
|
-
* in reverse order ensure that descendant are accessed first, before
|
156
|
-
* they get removed. Mixing XPath and modifications on a tree must be
|
157
|
-
* done carefully !
|
158
|
-
*/
|
159
|
-
for(i = size - 1; i >= 0; i--) {
|
160
|
-
assert(nodes->nodeTab[i]);
|
161
|
-
|
162
|
-
xmlNodeSetContent(nodes->nodeTab[i], value);
|
163
|
-
/*
|
164
|
-
* All the elements returned by an XPath query are pointers to
|
165
|
-
* elements from the tree *except* namespace nodes where the XPath
|
166
|
-
* semantic is different from the implementation in libxml2 tree.
|
167
|
-
* As a result when a returned node set is freed when
|
168
|
-
* xmlXPathFreeObject() is called, that routine must check the
|
169
|
-
* element type. But node from the returned set may have been removed
|
170
|
-
* by xmlNodeSetContent() resulting in access to freed data.
|
171
|
-
* This can be exercised by running
|
172
|
-
* valgrind xpath2 test3.xml '//discarded' discarded
|
173
|
-
* There is 2 ways around it:
|
174
|
-
* - make a copy of the pointers to the nodes from the result set
|
175
|
-
* then call xmlXPathFreeObject() and then modify the nodes
|
176
|
-
* or
|
177
|
-
* - remove the reference to the modified nodes from the node set
|
178
|
-
* as they are processed, if they are not namespace nodes.
|
179
|
-
*/
|
180
|
-
if (nodes->nodeTab[i]->type != XML_NAMESPACE_DECL)
|
181
|
-
nodes->nodeTab[i] = NULL;
|
182
|
-
}
|
183
|
-
}
|
184
|
-
|
185
|
-
#else
|
186
|
-
int main(void) {
|
187
|
-
fprintf(stderr, "XPath support not compiled in\n");
|
188
|
-
exit(1);
|
189
|
-
}
|
190
|
-
#endif
|
@@ -1,30 +0,0 @@
|
|
1
|
-
<?xml version="1.0"?>
|
2
|
-
<doc>
|
3
|
-
<parent>
|
4
|
-
<discarded>discarded</discarded>
|
5
|
-
<preserved/>
|
6
|
-
This text node must be discarded
|
7
|
-
<discarded>discarded</discarded>
|
8
|
-
<preserved>
|
9
|
-
content1
|
10
|
-
<child1/>
|
11
|
-
<child2>content2</child2>
|
12
|
-
<preserved>too</preserved>
|
13
|
-
<child2>content3</child2>
|
14
|
-
<preserved/>
|
15
|
-
<child2>content4</child2>
|
16
|
-
<preserved/>
|
17
|
-
<child2>content5</child2>
|
18
|
-
content6
|
19
|
-
</preserved>
|
20
|
-
This text node must be discarded
|
21
|
-
<discarded>discarded</discarded>
|
22
|
-
This text node must be discarded
|
23
|
-
<preserved/>
|
24
|
-
This text node must be discarded
|
25
|
-
<preserved/>
|
26
|
-
This text node must be discarded
|
27
|
-
<discarded>discarded</discarded>
|
28
|
-
This text node must be discarded
|
29
|
-
</parent>
|
30
|
-
</doc>
|