[xml] libxml current() Xpath extension



Hi Team,

I work on Yang RFC development. Yang RFC proposes an Xpath extension called current() as:

https://tools.ietf.org/html/rfc7950#section-10.1.1

10.1.1. current()

node-set current() The current() function takes no input parameters and returns a node set with the initial context node as its only member.
I have implemented this extension as shown below. This extension does seem to be working for simple Xpath expressions like: "current() > 0", but does not work when complex expressions are involved like:
"../../interface[name = current()/../ifname]/address/ip" 

Could you guys let me know if this implementation is proper? Your help is highly appreciated.


/*
 * ext_current () -- Defines the Xpath extension current(),
 * defined by Yang RFC.
 *
 * From Yang RFC 7950:
 *
 * The current() function takes no input parameters and returns a node
 * set with the initial context node as its only member.
 */
static void
ext_current (xmlXPathParserContextPtr ctxt, int nargs)
{
    /*
     * This function takes 0 args.
     */
    if (nargs != 0) {
        return;
    }

    /* Push the current context node onto Xpath Stack */
    valuePush(ctxt, xmlXPathNewNodeSet(ctxt->context->node));
}

/*
 * register_yang_xpath_extensions () -- Registers extensions defined by Yang
 * RFC. These extensions are implemented internally in Junos.
 */
static void
register_yang_xpath_extensions (xmlXPathContextPtr ctxt)
{
    int rc = 0;

    rc = xmlXPathRegisterFunc(ctxt, (const xmlChar *)"current",
                              ext_current);
    if (rc != 0)
        fprintf(stderr, "Error in registering current() func\n");
}


Regards,
Ram
 
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]