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 7402549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:46:14+00:00 2026-05-29T04:46:14+00:00

I am using libxml++-2.6 in C to create a really simple XML doc. What

  • 0

I am using libxml++-2.6 in C to create a really simple XML doc.

What is the technique for adding:

  • comments before the root node?
  • comments inside a node?

.

root_node = xmlNewNode( NULL, BAD_CAST "root" );
xmlDocSetRootElement( doc, root_node );

dtd = xmlCreateIntSubset(doc, BAD_CAST "root", NULL, BAD_CAST "root.dtd");

// neither of these seem to work

xmlNewComment( BAD_CAST "My Company, LLC" );

xmlNewDocComment    ( doc, BAD_CAST "My Company, LLC" );
  • 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-05-29T04:46:15+00:00Added an answer on May 29, 2026 at 4:46 am

    Before this got moved here I had posted my own answer in StackOverflow. Sorry to post it as an answer, but you can’t do formatted inopput in comments. 🙂

    This has worked for me;

    root_node = xmlNewNode( NULL, BAD_CAST "root" );
    xmlDocSetRootElement( doc, root_node );
    
    //==========================================================================
    // Comment block ABOVE the root node
    //==========================================================================
    cur_node = xmlAddPrevSibling( root_node, xmlNewComment( BAD_CAST copyright ));
               xmlAddNextSibling( cur_node,  xmlNewComment( BAD_CAST generated ));
    
    cur_node = x
    
    mlNewChild( root_node, NULL, BAD_CAST "Model" , BAD_CAST "FRED" );
    
    //==========================================================================
    // Comment block inside the root node but ABOVE the Model node
    //==========================================================================
    cur_node = xmlAddPrevSibling( root_node, xmlNewComment( BAD_CAST modinfo ));
               xmlAddNextSibling( cur_node,  xmlNewComment( BAD_CAST more_modinfo ));
    

    Notice that as you add a node, you put the comment before it then put additional linesof comment below that comment but still before the new doc/child element.

    Also notice, these comments can be outside the root node and not inside a visible node thatis a sibling of root.

    e.g.

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE TEST SYSTEM "testsystem.dtd">
    <!--Copyright (c) 2012 SuperTechnology, LLC.-->
    <!--Generated Jan 20 2012 16:15:11-->
    <root_node>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I create the following XML file, by perl script (Showing down) , using XML::LibXML:
I am using libxml-ruby for parsing XML. I can able to create the xml
I have a simple XML without namespace. I am using XML::LibXML::Reader to parse the
Please can somebody show me a simple example of parsing some HTML using libxml.
I am trying to validate an XML against schema using LibXML::Schema Validator CPAN module.
I am having trouble understanding / using name spaces with XML::LibXML package in Perl.
I need to create XML in Perl. From what I read, XML::LibXML is great
I am trying to read tags from XML using LibXML. I can print all
Where does one access the data from a parsed xml file when using libxml?
I am using XML::LibXML (Ver: 1.70). My xml input file looks like this: <?xml

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.