本文整理汇总了C++中xmlSearchNs函数的典型用法代码示例。如果您正苦于以下问题:C++ xmlSearchNs函数的具体用法?C++ xmlSearchNs怎么用?C++ xmlSearchNs使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xmlSearchNs函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: xmlSearchNs
xmlNode* child_node_list::create_element_(const std::string& qname)
{
// Split QName into prefix and local name.
std::pair<std::string, std::string> name_pair = detail::split_qname(qname);
const std::string& prefix = name_pair.first;
const std::string& name = name_pair.second;
// Find xmlns by prefix (if this child node list belongs to an element).
xmlNs* ns = 0;
if (raw_->type == XML_ELEMENT_NODE)
{
ns = xmlSearchNs( raw_->doc,
raw_,
prefix.empty() ? 0 : detail::to_xml_chars(prefix.c_str()) );
}
if (!prefix.empty() && ns == 0)
{
std::string what = "fail to create element " + qname
+ ": xmlns for prefix " + prefix + " not found";
throw bad_dom_operation(what);
}
// Create element under the xmlns.
xmlNode* px = xmlNewDocNode( raw_->doc,
ns,
detail::to_xml_chars(name.c_str()),
0 );
if (px == 0)
{
std::string what = "fail to create libxml2 element node for " + name;
throw internal_dom_error(what);
}
// Return the new element.
return px;
}
示例2: node_find_ns
xmlNsPtr node_find_ns(xmlNodePtr node) {
if (node->ns) {
return node->ns;
} else {
return xmlSearchNs(node->doc, node, NULL);
}
}
示例3: PatchCamFlags
virtual bool PatchCamFlags(xmlDocPtr doc, const char *uuid, const char *slot, const char *flags) {
bool uuid_match=false;
bool flags_set =false;
xmlNode *node = xmlDocGetRootElement(doc);
node = node ? node->children : NULL;
while(node && xmlStrcmp(node->name, (const xmlChar *)"Description"))
node=node->next;
node = node ? node->children : NULL;
while(node) {
if(node && !xmlStrcmp(node->name, (const xmlChar *)"component")) {
xmlNode *item = node->children;
while(item && xmlStrcmp(item->name, (const xmlChar *)"Description")) {
item = item->next;
} // while
xmlChar *about = item ? xmlGetProp(item, (const xmlChar *)"about") : NULL;
if(about) {
if (!xmlStrcmp(about, (const xmlChar *)"Platform")) {
xmlNode *sub = item->children;
while(sub) {
if(!xmlStrcmp(sub->name, (const xmlChar *)"UUID")) {
xmlChar *value=xmlNodeListGetString(doc, sub->children, 1);
if(value) {
uuid_match=!xmlStrcmp(value, (const xmlChar *)uuid);
xmlFree(value);
} // if
} // if
sub = sub->next;
} // while
} else if(!xmlStrcmp(about, (const xmlChar *)"CAM")) {
xmlNode *sub = item->children;
while(sub) {
if(!xmlStrcmp(sub->name, (const xmlChar *)"Slot")) {
xmlChar *value=xmlNodeListGetString(doc, sub->children, 1);
if(value) {
if (!xmlStrcmp(value, (const xmlChar *)slot)) {
xmlNode *tst = item->children;
while(tst) {
if(!xmlStrcmp(tst->name, (const xmlChar *)"Flags")) {
xmlReplaceNode(tst, xmlNewChild(item, xmlSearchNs(doc, tst, (const xmlChar *)"prf"), (const xmlChar *)"Flags", (const xmlChar *)flags));
xmlFreeNode(tst);
flags_set=true;
tst = NULL;
continue;
} // if
tst = tst->next;
} // while
} // if
xmlFree(value);
} // if
} // if
sub = sub->next;
} // while
} // if
xmlFree(about);
} // if
} // if
node = node->next;
} // while
return uuid_match && flags_set;
}; // PatchCamFlags
示例4: xsltGetSpecialNamespace
/**
* xsltGetSpecialNamespace:
* @ctxt: a transformation context
* @cur: the input node
* @URI: the namespace URI
* @prefix: the suggested prefix
* @out: the output node (or its parent)
*
* Find the right namespace value for this URI, if needed create
* and add a new namespace decalaration on the node
*
* Returns the namespace node to use or NULL
*/
xmlNsPtr
xsltGetSpecialNamespace(xsltTransformContextPtr ctxt, xmlNodePtr cur,
const xmlChar *URI, const xmlChar *prefix, xmlNodePtr out) {
xmlNsPtr ret;
static int prefixno = 1;
char nprefix[10];
if ((ctxt == NULL) || (cur == NULL) || (out == NULL) || (URI == NULL))
return(NULL);
if ((out->parent != NULL) &&
(out->parent->type == XML_ELEMENT_NODE) &&
(out->parent->ns != NULL) &&
(xmlStrEqual(out->parent->ns->href, URI)))
ret = out->parent->ns;
else
ret = xmlSearchNsByHref(out->doc, out, URI);
if (ret == NULL) {
if (prefix == NULL) {
do {
sprintf(nprefix, "ns%d", prefixno++);
ret = xmlSearchNs(out->doc, out, (xmlChar *)nprefix);
} while (ret != NULL);
prefix = (const xmlChar *) &nprefix[0];
}
if (out->type == XML_ELEMENT_NODE)
ret = xmlNewNs(out, URI, prefix);
}
return(ret);
}
示例5: slaxSetNs
/*
* Find or construct a (possibly temporary) namespace node
* for the "func" exslt library and put the given node into
* that namespace. We also have to add this as an "extension"
* namespace.
*/
static xmlNsPtr
slaxSetNs (slax_data_t *sdp, xmlNodePtr nodep,
const char *prefix, const xmlChar *uri, int local)
{
xmlNsPtr nsp;
xmlNodePtr root = xmlDocGetRootElement(sdp->sd_docp);
nsp = xmlSearchNs(sdp->sd_docp, root, (const xmlChar *) prefix);
if (nsp == NULL) {
nsp = xmlNewNs(root, uri, (const xmlChar *) prefix);
if (nsp == NULL) {
xmlParserError(sdp->sd_ctxt, "%s:%d: out of memory",
sdp->sd_filename, sdp->sd_line);
return NULL;
}
/*
* Since we added this namespace, we need to add it to the
* list of extension prefixes.
*/
slaxNodeAttribExtend(sdp, root,
ATT_EXTENSION_ELEMENT_PREFIXES, prefix, NULL);
}
if (nodep) {
/* Add a distinct namespace to the current node */
nsp = xmlNewNs(nodep, uri, (const xmlChar *) prefix);
if (local)
nodep->ns = nsp;
}
return nsp;
}
示例6: if
/**
* xlinkIsLink:
* @doc: the document containing the node
* @node: the node pointer itself
*
* Check whether the given node carries the attributes needed
* to be a link element (or is one of the linking elements issued
* from the (X)HTML DtDs).
* This routine don't try to do full checking of the link validity
* but tries to detect and return the appropriate link type.
*
* Returns the xlinkType of the node (XLINK_TYPE_NONE if there is no
* link detected.
*/
xlinkType
xlinkIsLink (xmlDocPtr doc, xmlNodePtr node) {
xmlChar *type = NULL, *role = NULL;
xlinkType ret = XLINK_TYPE_NONE;
if (node == NULL) return(XLINK_TYPE_NONE);
if (doc == NULL) doc = node->doc;
if ((doc != NULL) && (doc->type == XML_HTML_DOCUMENT_NODE)) {
/*
* This is an HTML document.
*/
} else if ((node->ns != NULL) &&
(xmlStrEqual(node->ns->href, XHTML_NAMESPACE))) {
/*
* !!!! We really need an IS_XHTML_ELEMENT function from HTMLtree.h @@@
*/
/*
* This is an XHTML element within an XML document
* Check whether it's one of the element able to carry links
* and in that case if it holds the attributes.
*/
}
/*
* We don't prevent a-priori having XML Linking constructs on
* XHTML elements
*/
type = xmlGetNsProp(node, BAD_CAST"type", XLINK_NAMESPACE);
if (type != NULL) {
if (xmlStrEqual(type, BAD_CAST "simple")) {
ret = XLINK_TYPE_SIMPLE;
} if (xmlStrEqual(type, BAD_CAST "extended")) {
role = xmlGetNsProp(node, BAD_CAST "role", XLINK_NAMESPACE);
if (role != NULL) {
xmlNsPtr xlink;
xlink = xmlSearchNs(doc, node, XLINK_NAMESPACE);
if (xlink == NULL) {
/* Humm, fallback method */
if (xmlStrEqual(role, BAD_CAST"xlink:external-linkset"))
ret = XLINK_TYPE_EXTENDED_SET;
} else {
xmlChar buf[200];
snprintf((char *) buf, sizeof(buf), "%s:external-linkset",
(char *) xlink->prefix);
buf[sizeof(buf) - 1] = 0;
if (xmlStrEqual(role, buf))
ret = XLINK_TYPE_EXTENDED_SET;
}
}
ret = XLINK_TYPE_EXTENDED;
}
}
if (type != NULL) xmlFree(type);
if (role != NULL) xmlFree(role);
return(ret);
}
示例7: xsltGetNamespace
/**
* xsltGetNamespace:
* @ctxt: a transformation context
* @cur: the input node
* @ns: the namespace
* @out: the output node (or its parent)
*
* Find a matching (prefix and ns-name) ns-declaration
* for the requested @ns->prefix and @ns->href in the result tree.
* If none is found then a new ns-declaration will be
* added to @resultElem. If, in this case, the given prefix is
* already in use, then a ns-declaration with a modified ns-prefix
* be we created.
*
* Called by:
* - xsltCopyPropList() (*not* anymore)
* - xsltShallowCopyElement()
* - xsltCopyTreeInternal() (*not* anymore)
* - xsltApplySequenceConstructor() (*not* in the refactored code),
* - xsltElement() (*not* anymore)
*
* Returns a namespace declaration or NULL in case of
* namespace fixup failures or API or internal errors.
*/
xmlNsPtr
xsltGetNamespace(xsltTransformContextPtr ctxt, xmlNodePtr cur, xmlNsPtr ns,
xmlNodePtr out)
{
if (ns == NULL)
return(NULL);
#ifdef XSLT_REFACTORED
/*
* Namespace exclusion and ns-aliasing is performed at
* compilation-time in the refactored code.
* Additionally, aliasing is not intended for non Literal
* Result Elements.
*/
return(xsltGetSpecialNamespace(ctxt, cur, ns->href, ns->prefix, out));
#else
{
xsltStylesheetPtr style;
const xmlChar *URI = NULL; /* the replacement URI */
if ((ctxt == NULL) || (cur == NULL) || (out == NULL))
return(NULL);
style = ctxt->style;
while (style != NULL) {
if (style->nsAliases != NULL)
URI = (const xmlChar *)
xmlHashLookup(style->nsAliases, ns->href);
if (URI != NULL)
break;
style = xsltNextImport(style);
}
if (URI == UNDEFINED_DEFAULT_NS) {
return(xsltGetSpecialNamespace(ctxt, cur, NULL, NULL, out));
#if 0
/*
* TODO: Removed, since wrong. If there was no default
* namespace in the stylesheet then this must resolve to
* the NULL namespace.
*/
xmlNsPtr dflt;
dflt = xmlSearchNs(cur->doc, cur, NULL);
if (dflt != NULL)
URI = dflt->href;
else
return NULL;
#endif
} else if (URI == NULL)
URI = ns->href;
return(xsltGetSpecialNamespace(ctxt, cur, URI, ns->prefix, out));
}
#endif
}
示例8: xsltElementAvailableFunction
/**
* xsltElementAvailableFunction:
* @ctxt: the XPath Parser context
* @nargs: the number of arguments
*
* Implement the element-available() XSLT function
* boolean element-available(string)
*/
void
xsltElementAvailableFunction(xmlXPathParserContextPtr ctxt, int nargs){
xmlXPathObjectPtr obj;
xmlChar *prefix, *name;
const xmlChar *nsURI = NULL;
xsltTransformContextPtr tctxt;
if (nargs != 1) {
xsltTransformError(xsltXPathGetTransformContext(ctxt), NULL, NULL,
"element-available() : expects one string arg\n");
ctxt->error = XPATH_INVALID_ARITY;
return;
}
xmlXPathStringFunction(ctxt, 1);
if ((ctxt->value == NULL) || (ctxt->value->type != XPATH_STRING)) {
xsltTransformError(xsltXPathGetTransformContext(ctxt), NULL, NULL,
"element-available() : invalid arg expecting a string\n");
ctxt->error = XPATH_INVALID_TYPE;
return;
}
obj = valuePop(ctxt);
tctxt = xsltXPathGetTransformContext(ctxt);
if (tctxt == NULL) {
xsltTransformError(xsltXPathGetTransformContext(ctxt), NULL, NULL,
"element-available() : internal error tctxt == NULL\n");
xmlXPathFreeObject(obj);
valuePush(ctxt, xmlXPathNewBoolean(0));
return;
}
name = xmlSplitQName2(obj->stringval, &prefix);
if (name == NULL) {
xmlNsPtr ns;
name = xmlStrdup(obj->stringval);
ns = xmlSearchNs(tctxt->inst->doc, tctxt->inst, NULL);
if (ns != NULL) nsURI = xmlStrdup(ns->href);
} else {
nsURI = xmlXPathNsLookup(ctxt->context, prefix);
if (nsURI == NULL) {
xsltTransformError(xsltXPathGetTransformContext(ctxt), NULL, NULL,
"element-available() : prefix %s is not bound\n", prefix);
}
}
if (xsltExtElementLookup(tctxt, name, nsURI) != NULL) {
valuePush(ctxt, xmlXPathNewBoolean(1));
} else {
valuePush(ctxt, xmlXPathNewBoolean(0));
}
xmlXPathFreeObject(obj);
if (name != NULL)
xmlFree(name);
if (prefix != NULL)
xmlFree(prefix);
}
示例9: attr_find_ns
xmlNsPtr attr_find_ns(xmlAttrPtr node) {
if (node->ns) {
return node->ns;
} else if (node->parent->ns) {
return node->parent->ns;
} else {
return xmlSearchNs(node->doc, node->parent, NULL);
}
}
示例10: epp_getSubtree
char *
epp_getSubtree(void *pool,
epp_command_data *cdata,
const char *xpath_expr,
int position)
{
char *subtree;
xmlBufferPtr buf;
xmlDocPtr doc;
xmlNodePtr node;
xmlXPathObjectPtr xpath_obj;
xmlXPathContextPtr xpath_ctx;
doc = (xmlDocPtr) cdata->parsed_doc;
xpath_ctx = (xmlXPathContextPtr) cdata->xpath_ctx;
xpath_obj = xmlXPathEvalExpression(BAD_CAST xpath_expr, xpath_ctx);
if (xpath_obj == NULL)
return NULL;
/* correct position for non-list elements */
if (position == 0) position++;
if (xmlXPathNodeSetGetLength(xpath_obj->nodesetval) < position) {
xmlXPathFreeObject(xpath_obj);
/* return empty string if the node is not there */
return epp_strdup(pool, "");
}
/*
* Get content of problematic tag. It's not so easy task. We have
* to declare namespaces defined higher in the tree which are relevant
* to the part of document being dumped. Fortunatelly there is a
* function from libxml library doing exactly that (xmlreconsiliatens).
*/
buf = xmlBufferCreate();
if (buf == NULL)
return NULL;
node = xmlXPathNodeSetItem(xpath_obj->nodesetval, position - 1);
if (node->ns != NULL) {
xmlNsPtr nsdef;
nsdef = xmlSearchNs(doc, node, node->ns->prefix);
if (nsdef != NULL)
xmlNewNs(node, nsdef->href, nsdef->prefix);
}
if (xmlNodeDump(buf, doc, node, 0, 0) < 0)
{
xmlXPathFreeObject(xpath_obj);
xmlBufferFree(buf);
return NULL;
}
subtree = epp_strdup(pool, (char *) buf->content);
xmlXPathFreeObject(xpath_obj);
xmlBufferFree(buf);
return subtree;
}
示例11: eXmlInvalid
std::string cXmlDoc::searchNs(const std::string& prefix, xmlNodePtr node) {
if (!m_doc)
throw eXmlInvalid("Tried to search namespace for bad document");
xmlNsPtr ns = xmlSearchNs(m_doc.get(), node?node:xmlDocGetRootElement(m_doc.get()), (prefix=="")?NULL:reinterpret_cast<const xmlChar*>(prefix.c_str()));
if (ns) {
return ns->href?string(reinterpret_cast<const char*>(ns->href)):"";
} else {
return "";
}
}
示例12: xmlSearchNs
const XMLNs *XMLElement::getNamespaceByPrefix(const char *prefix) const
{
xmlNs *ns = xmlSearchNs(doc.getRealDocument(), node, (const xmlChar *)prefix);
XMLObject *obj = scope->getXMLObjectFromLibXMLPtr(ns);
if (obj)
{
return static_cast < XMLNs * >(obj);
}
return new XMLNs(*this, ns);
}
示例13: InternalError
xmlNodePtr Node::createChild(const string &name, const string &prefix) const
{
xmlNs * ns = nullptr;
if ( Type() != NodeType::Element )
throw InternalError("Cannot add children to non-element node of type '" + TypeString(Type()) + "'");
if ( prefix.empty() )
{
ns = xmlSearchNs(_xml->doc, _xml, nullptr);
}
else
{
// use the existing namespace if one exists
ns = xmlSearchNs(_xml->doc, _xml, prefix.utf8());
if ( ns == nullptr )
throw InternalError(std::string("The namespace prefix '") + prefix.c_str() + "' is unknown");
}
return xmlNewNode(ns, name.utf8());
}
示例14: setNodeNameSpace
void XMLElement::setNodeNameSpace(const XMLNs & ns) const
{
xmlNs *n = ns.getRealNs();
if (n)
{
if (!n->prefix || !xmlSearchNs(doc.getRealDocument(), node, n->prefix))
{
n = xmlNewNs(node, (const xmlChar *)ns.getHref(), (const xmlChar *)ns.getPrefix());
}
xmlSetNs(node, n);
}
}
示例15: f_manage_input_xml
int f_manage_input_xml(const char *p_name,int s_type,audiovideo_t *p_audiovideo)
{
static xmlDocPtr p_doc;
xmlNodePtr p_node;
xmlNsPtr ns;
if (s_type) //read the file from p_name
{
p_doc = xmlParseFile(p_name);
p_node = xmlDocGetRootElement(p_doc);
if (p_node == NULL)
{
xmlFreeDoc(p_doc);
tc_log_error(__FILE__,"Invalid file format");
return(-1);
}
ns = xmlSearchNsByHref(p_doc, p_node, (const xmlChar *) "http://www.w3.org/2001/SMIL20/Language");
if (ns == NULL)
{
xmlFreeDoc(p_doc);
tc_log_error(__FILE__,"Invalid Namespace");
return(-1);
}
ns = xmlSearchNs(p_doc, p_node, (const xmlChar *) "smil2");
if (ns == NULL)
{
xmlFreeDoc(p_doc);
tc_log_error(__FILE__,"Invalid Namespace");
return(-1);
}
if (xmlStrcmp(p_node->name, (const xmlChar *) "smil"))
{
xmlFreeDoc(p_doc);
tc_log_error(__FILE__,"Invalid Namespace");
return(-1);
}
f_delete_unused_node(p_node);
memset(p_audiovideo,'\0',sizeof(audiovideo_t));
if(f_parse_tree(p_node,p_audiovideo))
return(1);
if (f_complete_tree(p_audiovideo))
return(1);
}
else
{
f_free_tree(p_audiovideo);
xmlFreeDoc(p_doc);
}
return(0);
}