110
110
XMLLINT_RETURN_OK = 0, /* No error */
111
XMLLINT_ERR_UNCLASS, /* Unclassified */
112
XMLLINT_ERR_DTD, /* Error in DTD */
113
XMLLINT_ERR_VALID, /* Validation error */
114
XMLLINT_ERR_RDFILE, /* CtxtReadFile error */
115
XMLLINT_ERR_SCHEMACOMP, /* Schema compilation */
116
XMLLINT_ERR_OUT, /* Error writing output */
117
XMLLINT_ERR_SCHEMAPAT, /* Error in schema pattern */
118
XMLLINT_ERR_RDREGIS, /* Error in Reader registration */
119
XMLLINT_ERR_MEM /* Out of memory error */
111
XMLLINT_ERR_UNCLASS = 1, /* Unclassified */
112
XMLLINT_ERR_DTD = 2, /* Error in DTD */
113
XMLLINT_ERR_VALID = 3, /* Validation error */
114
XMLLINT_ERR_RDFILE = 4, /* CtxtReadFile error */
115
XMLLINT_ERR_SCHEMACOMP = 5, /* Schema compilation */
116
XMLLINT_ERR_OUT = 6, /* Error writing output */
117
XMLLINT_ERR_SCHEMAPAT = 7, /* Error in schema pattern */
118
XMLLINT_ERR_RDREGIS = 8, /* Error in Reader registration */
119
XMLLINT_ERR_MEM = 9, /* Out of memory error */
120
XMLLINT_ERR_XPATH = 10 /* XPath evaluation error */
120
121
} xmllintReturnCode;
121
122
#ifdef LIBXML_DEBUG_ENABLED
122
123
static int shell = 0;
201
202
static xmlPatternPtr patternc = NULL;
202
203
static xmlStreamCtxtPtr patstream = NULL;
205
#ifdef LIBXML_XPATH_ENABLED
206
static const char *xpathquery = NULL;
204
208
static int options = XML_PARSE_COMPACT;
205
209
static int sax = 0;
206
210
static int oldxml10 = 0;
2051
2055
#endif /* LIBXML_READER_ENABLED */
2057
#ifdef LIBXML_XPATH_ENABLED
2058
/************************************************************************
2062
************************************************************************/
2064
static void doXPathDump(xmlXPathObjectPtr cur) {
2066
case XPATH_NODESET: {
2069
#ifdef LIBXML_OUTPUT_ENABLED
2070
xmlSaveCtxtPtr ctxt;
2072
if (cur->nodesetval->nodeNr <= 0) {
2073
fprintf(stderr, "XPath set is empty\n");
2074
progresult = XMLLINT_ERR_XPATH;
2077
ctxt = xmlSaveToFd(1, NULL, 0);
2079
fprintf(stderr, "Out of memory for XPath\n");
2080
progresult = XMLLINT_ERR_MEM;
2083
for (i = 0;i < cur->nodesetval->nodeNr;i++) {
2084
node = cur->nodesetval->nodeTab[i];
2085
xmlSaveTree(ctxt, node);
2089
printf("xpath returned %d nodes\n", cur->nodesetval->nodeNr);
2094
if (cur->boolval) printf("true");
2095
else printf("false");
2098
switch (xmlXPathIsInf(cur->floatval)) {
2103
printf("-Infinity");
2106
if (xmlXPathIsNaN(cur->floatval)) {
2109
printf("%0g", cur->floatval);
2114
printf("%s", (const char *) cur->stringval);
2116
case XPATH_UNDEFINED:
2117
fprintf(stderr, "XPath Object is uninitialized\n");
2118
progresult = XMLLINT_ERR_XPATH;
2121
fprintf(stderr, "XPath object of unexpected type\n");
2122
progresult = XMLLINT_ERR_XPATH;
2127
static void doXPathQuery(xmlDocPtr doc, const char *query) {
2128
xmlXPathContextPtr ctxt;
2129
xmlXPathObjectPtr res;
2131
ctxt = xmlXPathNewContext(doc);
2133
fprintf(stderr, "Out of memory for XPath\n");
2134
progresult = XMLLINT_ERR_MEM;
2137
ctxt->node = xmlDocGetRootElement(doc);
2138
res = xmlXPathEval(BAD_CAST query, ctxt);
2139
xmlXPathFreeContext(ctxt);
2142
fprintf(stderr, "XPath evaluation failure\n");
2143
progresult = XMLLINT_ERR_XPATH;
2147
xmlXPathFreeObject(res);
2149
#endif /* LIBXML_XPATH_ENABLED */
2053
2151
/************************************************************************
2055
2153
* Tree Test processing *
2419
#ifdef LIBXML_XPATH_ENABLED
2420
if (xpathquery != NULL) {
2421
doXPathQuery(doc, xpathquery);
2321
2425
#ifdef LIBXML_DEBUG_ENABLED
2322
2426
#ifdef LIBXML_XPATH_ENABLED
2553
2657
saveOpts |= XML_SAVE_FORMAT;
2659
#if defined(LIBXML_HTML_ENABLED) || defined(LIBXML_VALID_ENABLED)
2555
2661
saveOpts |= XML_SAVE_AS_XML;
2557
2664
if (output == NULL)
2558
2665
ctxt = xmlSaveToFd(1, encoding, saveOpts);
2946
3053
printf("\t--sax: do not build a tree but work just at the SAX level\n");
2947
3054
printf("\t--oldxml10: use XML-1.0 parsing rules before the 5th edition\n");
3055
#ifdef LIBXML_XPATH_ENABLED
3056
printf("\t--xpath expr: evaluate the XPath expression, inply --noout\n");
2949
3059
printf("\nLibxml project home page: http://xmlsoft.org/\n");
2950
3060
printf("To report bugs or get some help check: http://xmlsoft.org/bugs.html\n");
3286
3396
pattern = argv[i];
3398
#ifdef LIBXML_XPATH_ENABLED
3399
} else if ((!strcmp(argv[i], "-xpath")) ||
3400
(!strcmp(argv[i], "--xpath"))) {
3403
xpathquery = argv[i];
3288
3405
} else if ((!strcmp(argv[i], "-oldxml10")) ||
3289
3406
(!strcmp(argv[i], "--oldxml10"))) {
3636
#ifdef LIBXML_XPATH_ENABLED
3637
if ((!strcmp(argv[i], "-xpath")) ||
3638
(!strcmp(argv[i], "--xpath"))) {
3519
3643
if ((timing) && (repeat))
3521
3645
/* Remember file names. "-" means stdin. <sven@zen.org> */