1 /* usmb - mount SMB shares via FUSE and Samba
2 * Copyright (C) 2006-2010 Geoff Johnstone
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include <libxml/xmlreader.h>
19 #include <libxml/xpath.h>
20 #include <libxml/xpathInternals.h>
28 bool xml_validate_relaxng (xmlDocPtr doc
, const char *schema
)
30 xmlRelaxNGParserCtxtPtr rngpcptr
= NULL
;
31 xmlRelaxNGPtr rngptr
= NULL
;
32 xmlRelaxNGValidCtxtPtr rngvptr
= NULL
;
39 rngpcptr
= xmlRelaxNGNewMemParserCtxt (schema
, strlen (schema
));
43 rngptr
= xmlRelaxNGParse (rngpcptr
);
47 rngvptr
= xmlRelaxNGNewValidCtxt (rngptr
);
51 ret
= (0 == xmlRelaxNGValidateDoc (rngvptr
, doc
));
52 } while (false /*CONSTCOND*/);
55 xmlRelaxNGFreeValidCtxt (rngvptr
);
58 xmlRelaxNGFree (rngptr
);
61 xmlRelaxNGFreeParserCtxt (rngpcptr
);
67 bool xml_xpath_attr_value (xmlXPathContextPtr ctx
,
72 xmlXPathObjectPtr obj
;
76 assert (NULL
!= xpath
);
81 obj
= xmlXPathEval (BAD_CAST xpath
, ctx
);
84 DEBUG (fputs ("XPath evaluation error\n", stderr
));
90 if (XPATH_NODESET
!= obj
->type
)
92 DEBUG (fputs ("XPath evaluation didn't return a nodeset\n", stderr
));
96 if (NULL
== obj
->nodesetval
)
98 DEBUG (fputs ("nodesetval is NULL\n", stderr
));
102 if (1 != obj
->nodesetval
->nodeNr
)
104 DEBUG (fprintf (stderr
, "Nodeset has %d elements\n",
105 obj
->nodesetval
->nodeNr
));
109 tmp
= xmlGetProp (obj
->nodesetval
->nodeTab
[0], BAD_CAST attr
);
113 *out
= xstrdup ((char *)tmp
);
117 xmlXPathFreeObject (obj
);
120 } while (false /*CONSTCOND*/);
123 xmlXPathFreeObject (obj
);
128 bool xml_xpath_text (xmlXPathContextPtr ctx
, char *xpath
, char **out
)
130 xmlXPathObjectPtr obj
;
132 assert (NULL
!= ctx
);
133 assert (NULL
!= xpath
);
134 assert (NULL
!= out
);
138 DEBUG (fprintf (stderr
, "xml_xpath_text (%s)\n", xpath
));
140 obj
= xmlXPathEval (BAD_CAST xpath
, ctx
);
143 DEBUG (fputs ("XPath evaluation error\n", stderr
));
149 if (XPATH_NODESET
!= obj
->type
)
151 DEBUG (fputs ("XPath evaluation didn't return a nodeset\n", stderr
));
155 if (NULL
== obj
->nodesetval
)
157 DEBUG (fputs ("nodesetval is NULL\n", stderr
));
161 if (1 != obj
->nodesetval
->nodeNr
)
163 DEBUG (fprintf (stderr
, "Nodeset has %d elements\n",
164 obj
->nodesetval
->nodeNr
));
168 if (NULL
== obj
->nodesetval
->nodeTab
[0]->content
)
170 DEBUG (fputs ("Node has no text\n", stderr
));
174 *out
= xstrdup ((char *)obj
->nodesetval
->nodeTab
[0]->content
);
178 xmlXPathFreeObject (obj
);
181 } while (false /*CONSTCOND*/);
184 xmlXPathFreeObject (obj
);