1 /* usmb - mount SMB shares via FUSE and Samba
2 * Copyright (C) 2006-2008 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/>.
17 #include <libxml/xmlreader.h>
18 #include <libxml/xpath.h>
19 #include <libxml/xpathInternals.h>
27 bool xml_validate_relaxng (xmlDocPtr doc
, const char *schema
)
29 xmlRelaxNGParserCtxtPtr rngpcptr
= NULL
;
30 xmlRelaxNGPtr rngptr
= NULL
;
31 xmlRelaxNGValidCtxtPtr rngvptr
= NULL
;
38 rngpcptr
= xmlRelaxNGNewMemParserCtxt (schema
, strlen (schema
));
42 rngptr
= xmlRelaxNGParse (rngpcptr
);
46 rngvptr
= xmlRelaxNGNewValidCtxt (rngptr
);
50 ret
= (0 == xmlRelaxNGValidateDoc (rngvptr
, doc
));
51 } while (false /*CONSTCOND*/);
54 xmlRelaxNGFreeValidCtxt (rngvptr
);
57 xmlRelaxNGFree (rngptr
);
60 xmlRelaxNGFreeParserCtxt (rngpcptr
);
66 bool xml_xpath_attr_value (xmlXPathContextPtr ctx
,
68 const char *attribute
,
71 xmlXPathObjectPtr obj
;
75 assert (NULL
!= xpath
);
80 obj
= xmlXPathEval (BAD_CAST xpath
, ctx
);
83 DEBUG (fputs ("XPath evaluation error\n", stderr
));
89 if (XPATH_NODESET
!= obj
->type
)
91 DEBUG (fputs ("XPath evaluation didn't return a nodeset\n", stderr
));
95 if (NULL
== obj
->nodesetval
)
97 DEBUG (fputs ("nodesetval is NULL\n", stderr
));
101 if (1 != obj
->nodesetval
->nodeNr
)
103 DEBUG (fprintf (stderr
, "Nodeset has %d elements\n",
104 obj
->nodesetval
->nodeNr
));
108 tmp
= xmlGetProp (obj
->nodesetval
->nodeTab
[0], BAD_CAST attribute
);
112 *out
= xstrdup ((char *)tmp
);
116 xmlXPathFreeObject (obj
);
119 } while (false /*CONSTCOND*/);
122 xmlXPathFreeObject (obj
);
127 bool xml_xpath_text (xmlXPathContextPtr ctx
, char *xpath
, char **out
)
129 xmlXPathObjectPtr obj
;
131 assert (NULL
!= ctx
);
132 assert (NULL
!= xpath
);
133 assert (NULL
!= out
);
137 DEBUG (fprintf (stderr
, "xml_xpath_text (%s)\n", xpath
));
139 obj
= xmlXPathEval (BAD_CAST xpath
, ctx
);
142 DEBUG (fputs ("XPath evaluation error\n", stderr
));
148 if (XPATH_NODESET
!= obj
->type
)
150 DEBUG (fputs ("XPath evaluation didn't return a nodeset\n", stderr
));
154 if (NULL
== obj
->nodesetval
)
156 DEBUG (fputs ("nodesetval is NULL\n", stderr
));
160 if (1 != obj
->nodesetval
->nodeNr
)
162 DEBUG (fprintf (stderr
, "Nodeset has %d elements\n",
163 obj
->nodesetval
->nodeNr
));
167 if (NULL
== obj
->nodesetval
->nodeTab
[0]->content
)
169 DEBUG (fputs ("Node has no text\n", stderr
));
173 *out
= xstrdup ((char *)obj
->nodesetval
->nodeTab
[0]->content
);
177 xmlXPathFreeObject (obj
);
180 } while (false /*CONSTCOND*/);
183 xmlXPathFreeObject (obj
);