本文整理汇总了C++中rxml_raise函数的典型用法代码示例。如果您正苦于以下问题:C++ rxml_raise函数的具体用法?C++ rxml_raise怎么用?C++ rxml_raise使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rxml_raise函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rxml_parser_context_io
/* call-seq:
* XML::Parser::Context.io(io) -> XML::Parser::Context
*
* Creates a new parser context based on the specified io object.
*
* Parameters:
*
* io - A ruby IO object.
*/
static VALUE rxml_parser_context_io(VALUE klass, VALUE io)
{
xmlParserCtxtPtr ctxt;
xmlParserInputBufferPtr input;
xmlParserInputPtr stream;
input = xmlParserInputBufferCreateIO((xmlInputReadCallback) rxml_read_callback, NULL,
(void*)io, XML_CHAR_ENCODING_NONE);
ctxt = xmlNewParserCtxt();
if (!ctxt)
{
xmlFreeParserInputBuffer(input);
rxml_raise(&xmlLastError);
}
stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE);
if (!stream)
{
xmlFreeParserInputBuffer(input);
xmlFreeParserCtxt(ctxt);
rxml_raise(&xmlLastError);
}
inputPush(ctxt, stream);
return rxml_parser_context_wrap(ctxt);
}
示例2: rxml_node_child_set_aux
/*
* underlying for child_set and child_add, difference being
* former raises on implicit copy, latter does not.
*/
static VALUE rxml_node_child_set_aux(VALUE self, VALUE rnode)
{
xmlNodePtr pnode, chld, ret;
if (rb_obj_is_kind_of(rnode, cXMLNode) == Qfalse)
rb_raise(rb_eTypeError, "Must pass an XML::Node object");
Data_Get_Struct(self, xmlNode, pnode);
Data_Get_Struct(rnode, xmlNode, chld);
if (chld->parent != NULL || chld->doc != NULL)
rb_raise(
rb_eRuntimeError,
"Cannot move a node from one document to another with child= or <<. First copy the node before moving it.");
ret = xmlAddChild(pnode, chld);
if (ret == NULL)
{
rxml_raise(&xmlLastError);
}
else if (ret == chld)
{
/* child was added whole to parent and we need to return it as a new object */
return rxml_node_wrap(cXMLNode, chld);
}
/* else */
/* If it was a text node, then ret should be parent->last, so we will just return ret. */
return rxml_node_wrap(cXMLNode, ret);
}
示例3: rxml_document_validate_dtd
/*
* call-seq:
* document.validate(dtd) -> (true|false)
*
* Validate this document against the specified XML::DTD.
*/
static VALUE rxml_document_validate_dtd(VALUE self, VALUE dtd)
{
VALUE error = Qnil;
xmlValidCtxt ctxt;
xmlDocPtr xdoc;
xmlDtdPtr xdtd;
Data_Get_Struct(self, xmlDoc, xdoc);
Data_Get_Struct(dtd, xmlDtd, xdtd);
ctxt.userData = &error;
ctxt.error = (xmlValidityErrorFunc) LibXML_validity_error;
ctxt.warning = (xmlValidityWarningFunc) LibXML_validity_warning;
ctxt.nodeNr = 0;
ctxt.nodeTab = NULL;
ctxt.vstateNr = 0;
ctxt.vstateTab = NULL;
if (xmlValidateDtd(&ctxt, xdoc, xdtd))
{
return (Qtrue);
}
else
{
rxml_raise(&xmlLastError);
return Qfalse;
}
}
示例4: rxml_sax_parser_parse
/*
* call-seq:
* parser.parse -> (true|false)
*
* Parse the input XML, generating callbacks to the object
* registered via the +callbacks+ attributesibute.
*/
static VALUE rxml_sax_parser_parse(VALUE self)
{
int status;
VALUE context = rb_ivar_get(self, CONTEXT_ATTR);
xmlParserCtxtPtr ctxt;
Data_Get_Struct(context, xmlParserCtxt, ctxt);
ctxt->sax2 = 1;
ctxt->userData = (void*)rb_ivar_get(self, CALLBACKS_ATTR);
if (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler)
xmlFree(ctxt->sax);
ctxt->sax = (xmlSAXHandlerPtr) xmlMalloc(sizeof(rxml_sax_handler));
if (ctxt->sax == NULL)
rb_fatal("Not enough memory.");
memcpy(ctxt->sax, &rxml_sax_handler, sizeof(rxml_sax_handler));
status = xmlParseDocument(ctxt);
/* Now check the parsing result*/
if (status == -1 || !ctxt->wellFormed)
{
if (ctxt->myDoc)
xmlFreeDoc(ctxt->myDoc);
rxml_raise(&ctxt->lastError);
}
return Qtrue;
}
示例5: rxml_node_new_pi
/*
* call-seq:
* XML::Node.new_pi(name, content = nil) -> XML::Node
*
* Create a new pi node, optionally setting
* the node's content.
*
*/
static VALUE rxml_node_new_pi(int argc, VALUE *argv, VALUE klass)
{
VALUE name = Qnil;
VALUE content = Qnil;
xmlNodePtr xnode;
rb_scan_args(argc, argv, "11", &name, &content);
if (NIL_P(name))
{
rb_raise(rb_eRuntimeError, "You must provide me with a name for a PI.");
}
name = rb_obj_as_string(name);
if (NIL_P(content))
{
xnode = xmlNewPI((xmlChar*) StringValuePtr(name), NULL);
}
else
{
content = rb_obj_as_string(content);
xnode = xmlNewPI((xmlChar*) StringValuePtr(name), (xmlChar*) StringValueCStr(content));
}
if (xnode == NULL)
rxml_raise(&xmlLastError);
return rxml_node_wrap(xnode);
}
示例6: rxml_node_initialize
/*
* call-seq:
* XML::Node.initialize(name, content = nil, namespace = nil) -> XML::Node
*
* Creates a new element with the specified name, content and
* namespace. The content and namespace may be nil.
*/
static VALUE rxml_node_initialize(int argc, VALUE *argv, VALUE self)
{
VALUE name;
VALUE content;
VALUE ns;
xmlNodePtr xnode = NULL;
xmlNsPtr xns = NULL;
rb_scan_args(argc, argv, "12", &name, &content, &ns);
name = rb_obj_as_string(name);
if (!NIL_P(ns))
Data_Get_Struct(ns, xmlNs, xns);
xnode = xmlNewNode(xns, (xmlChar*) StringValuePtr(name));
if (xnode == NULL)
rxml_raise(&xmlLastError);
/* Link the Ruby object to the libxml object and vice-versa. */
xnode->_private = (void*) self;
DATA_PTR(self) = xnode;
if (!NIL_P(content))
rxml_node_content_set(self, content);
return self;
}
示例7: rxml_document_validate_schema
/*
* call-seq:
* document.validate_schema(schema) -> (true|false)
*
* Validate this document against the specified XML::Schema.
*
* If a block is provided it is used as an error handler for validaten errors.
* The block is called with two argument, the message and a flag indication
* if the message is an error (true) or a warning (false).
*/
static VALUE rxml_document_validate_schema(VALUE self, VALUE schema)
{
xmlSchemaValidCtxtPtr vptr;
xmlDocPtr xdoc;
xmlSchemaPtr xschema;
int is_invalid;
Data_Get_Struct(self, xmlDoc, xdoc);
Data_Get_Struct(schema, xmlSchema, xschema);
vptr = xmlSchemaNewValidCtxt(xschema);
xmlSchemaSetValidErrors(vptr,
(xmlSchemaValidityErrorFunc) LibXML_validity_error,
(xmlSchemaValidityWarningFunc) LibXML_validity_warning, NULL);
is_invalid = xmlSchemaValidateDoc(vptr, xdoc);
xmlSchemaFreeValidCtxt(vptr);
if (is_invalid)
{
rxml_raise(&xmlLastError);
return Qfalse;
}
else
{
return Qtrue;
}
}
示例8: rxml_reader_file
/* call-seq:
* XML::Reader.file(path) -> XML::Reader
* XML::Reader.file(path, :encoding => XML::Encoding::UTF_8,
* :options => XML::Parser::Options::NOENT) -> XML::Parser
*
* Creates a new reader by parsing the specified file or uri.
*
* You may provide an optional hash table to control how the
* parsing is performed. Valid options are:
*
* encoding - The document encoding, defaults to nil. Valid values
* are the encoding constants defined on XML::Encoding.
* options - Controls the execution of the parser, defaults to 0.
* Valid values are the constants defined on
* XML::Parser::Options. Mutliple options can be combined
* by using Bitwise OR (|).
*/
static VALUE rxml_reader_file(int argc, VALUE *argv, VALUE klass)
{
xmlTextReaderPtr xreader;
VALUE path;
VALUE options;
const char *xencoding = NULL;
int xoptions = 0;
rb_scan_args(argc, argv, "11", &path, &options);
Check_Type(path, T_STRING);
if (!NIL_P(options))
{
VALUE encoding = Qnil;
VALUE parserOptions = Qnil;
Check_Type(options, T_HASH);
encoding = rb_hash_aref(options, base_uri_SYMBOL);
xencoding = NIL_P(encoding) ? NULL : xmlGetCharEncodingName(NUM2INT(encoding));
parserOptions = rb_hash_aref(options, OPTIONS_SYMBOL);
xoptions = NIL_P(parserOptions) ? 0 : NUM2INT(parserOptions);
}
xreader = xmlReaderForFile(StringValueCStr(path), xencoding, xoptions);
if (xreader == NULL)
rxml_raise(&xmlLastError);
return rxml_reader_wrap(xreader);
}
示例9: rxml_node_modify_dom
static VALUE rxml_node_modify_dom(VALUE self, VALUE target,
xmlNodePtr (*xmlFunc)(xmlNodePtr, xmlNodePtr))
{
xmlNodePtr xnode, xtarget, xresult;
if (rb_obj_is_kind_of(target, cXMLNode) == Qfalse)
rb_raise(rb_eTypeError, "Must pass an XML::Node object");
xnode = rxml_get_xnode(self);
xtarget = rxml_get_xnode(target);
if (xtarget->doc != NULL && xtarget->doc != xnode->doc)
rb_raise(eXMLError, "Nodes belong to different documents. You must first import the node by calling XML::Document.import");
xmlUnlinkNode(xtarget);
/* This target node could be freed here. */
xresult = xmlFunc(xnode, xtarget);
if (!xresult)
rxml_raise(&xmlLastError);
/* Was the target freed? If yes, then wrap the new node */
if (xresult != xtarget)
{
RDATA(target)->data = xresult;
xresult->_private = (void*) target;
}
return target;
}
示例10: rxml_document_validate_relaxng
/*
* call-seq:
* document.validate_schema(relaxng) -> (true|false)
*
* Validate this document against the specified XML::RelaxNG.
*
* If a block is provided it is used as an error handler for validaten errors.
* The block is called with two argument, the message and a flag indication
* if the message is an error (true) or a warning (false).
*/
static VALUE rxml_document_validate_relaxng(VALUE self, VALUE relaxng)
{
xmlRelaxNGValidCtxtPtr vptr;
xmlDocPtr xdoc;
xmlRelaxNGPtr xrelaxng;
int is_invalid;
Data_Get_Struct(self, xmlDoc, xdoc);
Data_Get_Struct(relaxng, xmlRelaxNG, xrelaxng);
vptr = xmlRelaxNGNewValidCtxt(xrelaxng);
xmlRelaxNGSetValidErrors(vptr,
(xmlRelaxNGValidityErrorFunc) LibXML_validity_error,
(xmlRelaxNGValidityWarningFunc) LibXML_validity_warning, NULL);
is_invalid = xmlRelaxNGValidateDoc(vptr, xdoc);
xmlRelaxNGFreeValidCtxt(vptr);
if (is_invalid)
{
rxml_raise(&xmlLastError);
return Qfalse;
}
else
{
return Qtrue;
}
}
示例11: rxml_xpath_context_find
/*
* call-seq:
* context.find("xpath") -> true|false|number|string|XML::XPath::Object
*
* Executes the provided xpath function. The result depends on the execution
* of the xpath statement. It may be true, false, a number, a string or
* a node set.
*/
static VALUE rxml_xpath_context_find(VALUE self, VALUE xpath_expr)
{
xmlXPathContextPtr xctxt;
xmlXPathObjectPtr xobject;
xmlXPathCompExprPtr xcompexpr;
VALUE result;
Data_Get_Struct(self, xmlXPathContext, xctxt);
if (TYPE(xpath_expr) == T_STRING)
{
VALUE expression = rb_check_string_type(xpath_expr);
xobject = xmlXPathEval((xmlChar*) StringValueCStr(expression), xctxt);
}
else if (rb_obj_is_kind_of(xpath_expr, cXMLXPathExpression))
{
Data_Get_Struct(xpath_expr, xmlXPathCompExpr, xcompexpr);
xobject = xmlXPathCompiledEval(xcompexpr, xctxt);
}
else
{
rb_raise(rb_eTypeError,
"Argument should be an intance of a String or XPath::Expression");
}
if (xobject == NULL)
{
/* xmlLastError is different than xctxt->lastError. Use
xmlLastError since it has the message set while xctxt->lastError
does not. */
xmlErrorPtr xerror = xmlGetLastError();
rxml_raise(xerror);
}
switch (xobject->type)
{
case XPATH_NODESET:
result = rxml_xpath_object_wrap(xctxt->doc, xobject);
break;
case XPATH_BOOLEAN:
result = (xobject->boolval != 0) ? Qtrue : Qfalse;
xmlXPathFreeObject(xobject);
break;
case XPATH_NUMBER:
result = rb_float_new(xobject->floatval);
xmlXPathFreeObject(xobject);
break;
case XPATH_STRING:
result = rb_str_new2((const char*)xobject->stringval);
xmlXPathFreeObject(xobject);
break;
default:
result = Qnil;
xmlXPathFreeObject(xobject);
}
return result;
}
示例12: rxml_xpath_context_disable_cache
/*
* call-seq:
* context.disable_cache
*
* Disables an XPath::Context's built-in cache.
*/
static VALUE
rxml_xpath_context_disable_cache(VALUE self)
{
xmlXPathContextPtr xctxt;
Data_Get_Struct(self, xmlXPathContext, xctxt);
if (xmlXPathContextSetCache(xctxt, 0, 0, 0) == -1)
rxml_raise(&xmlLastError);
return self;
}
示例13: rxml_node_new_text
/*
* call-seq:
* XML::Node.new_text(content) -> XML::Node
*
* Create a new text node.
*
*/
static VALUE rxml_node_new_text(VALUE klass, VALUE content)
{
xmlNodePtr xnode;
Check_Type(content, T_STRING);
content = rb_obj_as_string(content);
xnode = xmlNewText((xmlChar*) StringValueCStr(content));
if (xnode == NULL)
rxml_raise(&xmlLastError);
return rxml_node_wrap(xnode);
}
示例14: rxml_xpath_expression_initialize
/* call-seq:
* XPath::Expression.new(expression) -> XPath::Expression
*
* Compiles an XPatch expression. This improves performance
* when an XPath expression is called multiple times.
*
* doc = XML::Document.string('<header><first>hi</first></header>')
* expr = XPath::Expression.new('//first')
* nodes = doc.find(expr)
*/
static VALUE rxml_xpath_expression_initialize(VALUE self, VALUE expression)
{
xmlXPathCompExprPtr compexpr = xmlXPathCompile((const xmlChar*)StringValueCStr(expression));
if (compexpr == NULL)
{
xmlErrorPtr xerror = xmlGetLastError();
rxml_raise(xerror);
}
DATA_PTR( self) = compexpr;
return self;
}
示例15: rxml_reader_document
/*
* call-seq:
* XML::Reader.document(doc) -> XML::Reader
*
* Create an new reader for the specified document.
*/
VALUE rxml_reader_document(VALUE klass, VALUE doc)
{
xmlDocPtr xdoc;
xmlTextReaderPtr xreader;
Data_Get_Struct(doc, xmlDoc, xdoc);
xreader = xmlReaderWalker(xdoc);
if (xreader == NULL)
rxml_raise(&xmlLastError);
return rxml_reader_wrap(xreader);
}