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

  • Home
  • SEARCH
  • 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 7882885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:23:27+00:00 2026-06-03T04:23:27+00:00

I am using libxml in C and this is how I create xml: xmlDocPtr

  • 0

I am using libxml in C and this is how I create xml:

xmlDocPtr createXmlSegment(char *headerContent, char *dataContent)
{
  xmlDocPtr doc;
  doc = xmlNewDoc(BAD_CAST "1.0");
  xmlNodePtr rdt, header, data;
  rdt = xmlNewNode(NULL, BAD_CAST "rdt-segment");
  xmlSetProp(rdt, "id", "1");
  header = xmlNewNode(NULL,BAD_CAST "header");
  data = xmlNewNode(NULL, BAD_CAST "data");
  xmlNodeSetContent(header, BAD_CAST headerContent);
  xmlNodeSetContent(data, BAD_CAST dataContent);
  xmlAddChild(rdt, header);
  xmlAddChild(rdt, data);
  xmlDocSetRootElement(doc, rdt);
  return doc;
}

and this is how I want get data from that xml:

int getDataFromXmlSegment(char *data, char *header, char *content)
{
  xmlDocPtr doc = xmlReadMemory(data, strlen(data), NULL, NULL, XML_PARSE_NOBLANKS);
  xmlNode *rdt = doc->children;
  xmlNode *headerNode = rdt->children;
  header = (char *)headerNode->content;
  content = (char *)headerNode->next->content;
  printf("header: %s, content: %s", header, content);
  return EXIT_SUCCESS;
}

When I test headerNode->name or ->next->name then the names are correct (it´s names of that elements) but content returns null. Anyone knows where is problem?

  • 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-03T04:23:29+00:00Added an answer on June 3, 2026 at 4:23 am

    Short answer: use xmlNodeGetContent.

    Element nodes themselves don’t contain content. Instead, they have children text nodes, and those contain content. The contents of an element may be a mix of text and tags, and this allows it to maintain the ordering, represent entities, etc.

    You could iterate over the child nodes and look at THEIR content members, but xmlNodeGetContent does that for you, and will handle child tags and entities properly.

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

Sidebar

Related Questions

using (var file_stream = File.Create(users.xml)) { var serializer = new XmlSerializer(typeof(PasswordManager)); serializer.Serialize(file_stream, this); file_stream.Close();
I am using XML::LibXML (Ver: 1.70). My xml input file looks like this: <?xml
My XML looks like this- <info> <name>NameGoesHere</name> <age>99</age> </info> Using XML::LibXML::Reader, I would like
This is follow-up to: using xslt to create an xml file in c <element1
This is a xml structure that I want to parse using libxml parsing. How
Some XML::LibXML methods return arrays instead of references to arrays. Instead of doing this:
i'm trying to implement paging in xml using this code and got around to
I am having trouble understanding / using name spaces with XML::LibXML package in Perl.
I am trying to read tags from XML using LibXML. I can print all
I'm using PHP xmlreader to validate and parse xml data. This xml is validated

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.