How to retrieve variables from POST XML data

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

 



Hi All,

 

Can please someone provide an example of how to retrieve values from POST xml data.

 

I use ap_xml_parse_input() to get and parse XML POST.

 

 

 

 

 

 

 

 

 

 

 

 

At the moment I can retrieve everything, including elements, attributes, cdata, but the actual string values.  How should I retrieve the values of “Tove”, “Jani”, “Reminder”, etc?

<xml>

<note urgency="important">

<to>Tove</to>

<from>Jani</from>

<heading>Reminder</heading>

<body>Don't forget me this weekend!</body>

</note>

<note1 urgency="urgent">

<to>Rose</to>

<from>Smith</from>

<heading>Reminder</heading>

<body>Give me a call.</body>

</note1>

</xml>

 

 

Here is a small code snippet:

 

 

 

static int example_handler(request_rec *r) {

 

apr_xml_doc *xmlData;

 

ap_rprintf(r, "Hello\n");

 

    xmlData = readPost(r);

ap_rprintf(r, "Read POST...\n");

    if (xmlData) {

ap_rprintf(r, "xmlData != NULL\n XML POST read successfully...\n");

ap_rprintf(r, "Root Element == %s\n", xmlData->root->name);

ap_rprintf(r, "Root First child = %s\n", xmlData->root->first_child->name);

ap_rprintf(r, "Root Last child = %s\n", xmlData->root->last_child->name);

ap_rprintf(r, "Root Next = %s\n", xmlData->root->first_child->next->name);

ap_rprintf(r, "ATTR_VAL = %s\n", xmlData->root->first_child->next->attr->value);

ap_rprintf(r, "private = %s\n", (char*)xmlData->root->first_child->next->priv);

ap_rprintf(r, "NALLOC = %i\n", xmlData->namespaces->nalloc);

ap_rprintf(r, "NELTS = %i\n", xmlData->namespaces->nelts);

ap_rprintf(r, "ELTS = %s\n", xmlData->namespaces->elts);

}

Return OK;

 

}

 

 

apr_xml_doc* readPost(request_rec *r) {

    apr_array_header_t *pairs = NULL;

    apr_xml_doc* pdoc = NULL;

    apr_off_t len;

    apr_size_t size;

    int res;

    int i = 0;

    char *buffer;

 

 

        res = ap_xml_parse_input(r,  &pdoc);

    if (res != OK || !pdoc) {ap_rprintf(r, "res = %i\n", res); ap_rprintf(r, "Failed...\n"); return NULL;} /* Return NULL if we failed or if there are is no POST data */

 

    return pdoc;

}

 

 

 

Thank you J


[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux