Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7878379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:38:33+00:00 2026-06-03T03:38:33+00:00

Is there an easy way how can I get in C char * from

  • 0

Is there an easy way how can I get in C char * from xmlNode in libxml2? I want to get something like this: "<root id="01"><head>some</head><data>information</data></root>" What should be in char *getStringFromXmlNode(xmlNode *node)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T03:38:35+00:00Added an answer on June 3, 2026 at 3:38 am

    Something like this.

    #include <libxml/parser.h>
    #include <libxml/xpath.h>
    #include <libxml/tree.h>
    #include <string.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    void* getValueFromXML(xmlDocPtr doc, xmlChar *xpath )
    {
        xmlXPathObjectPtr result;
        xmlNodeSetPtr nodeset;
        xmlChar *keyword;
        char *copiedStringPtr;
    
        // Nodes are
        // parse the xml document and find those nodes that meet the criteria of the xpath.
        result = getnodeset(doc, xpath);
    
        // if it parsed and found anything
        if (result)
        {
            // get the nodes that matched.
            nodeset = result->nodesetval;
            // go through each Node. There are nodeNr number of nodes.
            // nodeset is the seta of all nodes that met the xpath criteria
            // For the API look here http://xmlsoft.org/html/libxml-xpath.html
            if (nodeset->nodeNr>1)
            {
                printf("Returned more than one value. Fix the xpath\n");
                return NULL;
            }
    
            keyword = xmlNodeListGetString(doc, nodeset->nodeTab[0]->xmlChildrenNode, 1);
            //printf("keyword: %s\n", keyword);
    
            copiedStringPtr = strdup((const char *)keyword);
    
    
            xmlFree(keyword);
            xmlXPathFreeObject (result);
        }
    
        return copiedStringPtr;
    }
    
    
    
    xmlXPathObjectPtr getnodeset (xmlDocPtr doc, xmlChar *xpath)
    {
    
        xmlXPathContextPtr context; //http://xmlsoft.org/html/libxml-xpath.html#xmlXPathContext
        xmlXPathObjectPtr result; // http://xmlsoft.org/html/libxml-xpath.html#xmlXPathObject
    
        // http://xmlsoft.org/html/libxml-xpath.html#xmlXPathNewContext
        context = xmlXPathNewContext(doc);
        if (context == NULL)
        {
            printf("Error in xmlXPathNewContext\n");
            return NULL;
        }
    
        //http://xmlsoft.org/html/libxml-xpath.html#xmlXPathEvalExpression
        result = xmlXPathEvalExpression(xpath, context);
        xmlXPathFreeContext(context);
        if (result == NULL)
        {
            printf("Error in xmlXPathEvalExpression\n");
            return NULL;
        }
        if (xmlXPathNodeSetIsEmpty(result->nodesetval))
        {
            xmlXPathFreeObject(result);
            printf("No result\n");
            return NULL;
        }
        return result;
    }
    

    At least I think that is what you were asking. Hope it helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there an easy way (like a free program) that can covert c/c++ code
Is there a really easy way I can take an array of JSON objects
Is there an easy way to write C code that can access its Git
Is there an easy way to limit the number of times a view can
Is there an easy way to manipulate PNGs in Java? I know I can
Can I install Pinax on Windows Environment? Is there a easy way? Which environment
Is there an easy way to set the volume from managed .net code?
When using socket.IO in a Node.js server, is there an easy way to get
Is there an easy way to create a folder structure output from an XML
I'm assuming there is an easy way to do this, but I think that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.