2006-02-16 22:50:52 +00:00
|
|
|
/*
|
2012-12-13 18:13:21 +00:00
|
|
|
* virxml.c: helper APIs for dealing with XML documents
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005, 2007-2012 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Daniel Veillard <veillard@redhat.com>
|
2006-02-16 22:50:52 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __VIR_XML_H__
|
2010-03-09 18:22:22 +00:00
|
|
|
# define __VIR_XML_H__
|
2006-02-16 22:50:52 +00:00
|
|
|
|
2010-03-09 18:22:22 +00:00
|
|
|
# include "internal.h"
|
2006-02-16 22:50:52 +00:00
|
|
|
|
2010-03-09 18:22:22 +00:00
|
|
|
# include <libxml/parser.h>
|
|
|
|
# include <libxml/tree.h>
|
|
|
|
# include <libxml/xpath.h>
|
2006-02-16 22:50:52 +00:00
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
int virXPathBoolean(const char *xpath,
|
2008-04-10 16:54:54 +00:00
|
|
|
xmlXPathContextPtr ctxt);
|
2010-02-04 21:52:34 +00:00
|
|
|
char * virXPathString(const char *xpath,
|
2008-04-10 16:54:54 +00:00
|
|
|
xmlXPathContextPtr ctxt);
|
2010-02-04 21:52:34 +00:00
|
|
|
char * virXPathStringLimit(const char *xpath,
|
|
|
|
size_t maxlen,
|
|
|
|
xmlXPathContextPtr ctxt);
|
|
|
|
int virXPathNumber(const char *xpath,
|
2008-04-10 16:54:54 +00:00
|
|
|
xmlXPathContextPtr ctxt,
|
|
|
|
double *value);
|
2011-01-13 22:09:18 +00:00
|
|
|
int virXPathInt(const char *xpath,
|
|
|
|
xmlXPathContextPtr ctxt,
|
|
|
|
int *value);
|
|
|
|
int virXPathUInt(const char *xpath,
|
|
|
|
xmlXPathContextPtr ctxt,
|
|
|
|
unsigned int *value);
|
2010-02-04 21:52:34 +00:00
|
|
|
int virXPathLong(const char *xpath,
|
2008-04-10 16:54:54 +00:00
|
|
|
xmlXPathContextPtr ctxt,
|
|
|
|
long *value);
|
2011-01-13 22:09:18 +00:00
|
|
|
int virXPathULong(const char *xpath,
|
2008-07-11 10:48:34 +00:00
|
|
|
xmlXPathContextPtr ctxt,
|
|
|
|
unsigned long *value);
|
2010-02-04 21:52:34 +00:00
|
|
|
int virXPathULongLong(const char *xpath,
|
2009-02-24 14:54:30 +00:00
|
|
|
xmlXPathContextPtr ctxt,
|
|
|
|
unsigned long long *value);
|
2011-01-13 22:09:18 +00:00
|
|
|
int virXPathLongLong(const char *xpath,
|
2010-02-02 17:49:09 +00:00
|
|
|
xmlXPathContextPtr ctxt,
|
|
|
|
long long *value);
|
2011-01-13 22:09:18 +00:00
|
|
|
int virXPathLongHex(const char *xpath,
|
2009-02-24 14:53:30 +00:00
|
|
|
xmlXPathContextPtr ctxt,
|
|
|
|
long *value);
|
2010-02-04 21:52:34 +00:00
|
|
|
int virXPathULongHex(const char *xpath,
|
2009-02-24 14:53:30 +00:00
|
|
|
xmlXPathContextPtr ctxt,
|
|
|
|
unsigned long *value);
|
2010-02-04 21:52:34 +00:00
|
|
|
xmlNodePtr virXPathNode(const char *xpath,
|
2008-04-10 16:54:54 +00:00
|
|
|
xmlXPathContextPtr ctxt);
|
2010-02-04 21:52:34 +00:00
|
|
|
int virXPathNodeSet(const char *xpath,
|
2008-04-10 16:54:54 +00:00
|
|
|
xmlXPathContextPtr ctxt,
|
|
|
|
xmlNodePtr **list);
|
2008-07-11 16:23:36 +00:00
|
|
|
char * virXMLPropString(xmlNodePtr node,
|
|
|
|
const char *name);
|
2011-12-07 22:06:18 +00:00
|
|
|
long virXMLChildElementCount(xmlNodePtr node);
|
2008-07-11 16:23:36 +00:00
|
|
|
|
2011-08-18 21:01:36 +00:00
|
|
|
/* Internal function; prefer the macros below. */
|
2010-02-24 20:44:47 +00:00
|
|
|
xmlDocPtr virXMLParseHelper(int domcode,
|
|
|
|
const char *filename,
|
|
|
|
const char *xmlStr,
|
2011-08-18 21:01:36 +00:00
|
|
|
const char *url,
|
|
|
|
xmlXPathContextPtr *pctxt);
|
2010-02-24 20:44:47 +00:00
|
|
|
|
2012-10-29 12:15:55 +00:00
|
|
|
const char *virXMLPickShellSafeComment(const char *str1, const char *str2);
|
2011-08-18 21:01:36 +00:00
|
|
|
/**
|
|
|
|
* virXMLParse:
|
|
|
|
* @filename: file to parse, or NULL for string parsing
|
|
|
|
* @xmlStr: if @filename is NULL, a string to parse
|
|
|
|
* @url: if @filename is NULL, an optional filename to attribute the parse to
|
|
|
|
*
|
|
|
|
* Parse xml from either a file or a string.
|
|
|
|
*
|
|
|
|
* Return the parsed document object, or NULL on failure.
|
|
|
|
*/
|
2010-02-24 20:44:47 +00:00
|
|
|
# define virXMLParse(filename, xmlStr, url) \
|
2011-08-18 21:01:36 +00:00
|
|
|
virXMLParseHelper(VIR_FROM_THIS, filename, xmlStr, url, NULL)
|
2010-02-24 20:44:47 +00:00
|
|
|
|
2011-08-18 21:01:36 +00:00
|
|
|
/**
|
|
|
|
* virXMLParseString:
|
|
|
|
* @xmlStr: a string to parse
|
|
|
|
* @url: an optional filename to attribute the parse to
|
|
|
|
*
|
|
|
|
* Parse xml from a string.
|
|
|
|
*
|
|
|
|
* Return the parsed document object, or NULL on failure.
|
|
|
|
*/
|
2010-02-24 20:44:47 +00:00
|
|
|
# define virXMLParseString(xmlStr, url) \
|
2011-08-18 21:01:36 +00:00
|
|
|
virXMLParseHelper(VIR_FROM_THIS, NULL, xmlStr, url, NULL)
|
2010-02-24 20:44:47 +00:00
|
|
|
|
2011-08-18 21:01:36 +00:00
|
|
|
/**
|
|
|
|
* virXMLParseFile:
|
|
|
|
* @filename: file to parse
|
|
|
|
*
|
|
|
|
* Parse xml from a file.
|
|
|
|
*
|
|
|
|
* Return the parsed document object, or NULL on failure.
|
|
|
|
*/
|
2010-02-24 20:44:47 +00:00
|
|
|
# define virXMLParseFile(filename) \
|
2011-08-18 21:01:36 +00:00
|
|
|
virXMLParseHelper(VIR_FROM_THIS, filename, NULL, NULL, NULL)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virXMLParseCtxt:
|
|
|
|
* @filename: file to parse, or NULL for string parsing
|
|
|
|
* @xmlStr: if @filename is NULL, a string to parse
|
|
|
|
* @url: if @filename is NULL, an optional filename to attribute the parse to
|
|
|
|
* @pctxt: if non-NULL, populate with a new context object on success,
|
|
|
|
* with (*pctxt)->node pre-set to the root node
|
|
|
|
*
|
|
|
|
* Parse xml from either a file or a string.
|
|
|
|
*
|
|
|
|
* Return the parsed document object, or NULL on failure.
|
|
|
|
*/
|
|
|
|
# define virXMLParseCtxt(filename, xmlStr, url, pctxt) \
|
|
|
|
virXMLParseHelper(VIR_FROM_THIS, filename, xmlStr, url, pctxt)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virXMLParseStringCtxt:
|
|
|
|
* @xmlStr: a string to parse
|
|
|
|
* @url: an optional filename to attribute the parse to
|
|
|
|
* @pctxt: if non-NULL, populate with a new context object on success,
|
|
|
|
* with (*pctxt)->node pre-set to the root node
|
|
|
|
*
|
|
|
|
* Parse xml from a string.
|
|
|
|
*
|
|
|
|
* Return the parsed document object, or NULL on failure.
|
|
|
|
*/
|
|
|
|
# define virXMLParseStringCtxt(xmlStr, url, pctxt) \
|
|
|
|
virXMLParseHelper(VIR_FROM_THIS, NULL, xmlStr, url, pctxt)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virXMLParseFileCtxt:
|
|
|
|
* @filename: file to parse
|
|
|
|
* @pctxt: if non-NULL, populate with a new context object on success,
|
|
|
|
* with (*pctxt)->node pre-set to the root node
|
|
|
|
*
|
|
|
|
* Parse xml from a file.
|
|
|
|
*
|
|
|
|
* Return the parsed document object, or NULL on failure.
|
|
|
|
*/
|
|
|
|
# define virXMLParseFileCtxt(filename, pctxt) \
|
|
|
|
virXMLParseHelper(VIR_FROM_THIS, filename, NULL, NULL, pctxt)
|
2010-02-24 20:44:47 +00:00
|
|
|
|
2011-10-06 09:57:06 +00:00
|
|
|
int virXMLSaveFile(const char *path,
|
|
|
|
const char *warnName,
|
|
|
|
const char *warnCommand,
|
|
|
|
const char *xml);
|
|
|
|
|
2006-03-15 12:13:25 +00:00
|
|
|
#endif /* __VIR_XML_H__ */
|