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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:47:09+00:00 2026-05-21T03:47:09+00:00

i am writing a c++ function that will parse .xml file. i Used system(grep);

  • 0

i am writing a c++ function that will parse .xml file.
i Used system(“grep”); type system call to use linux command. now my problem is that i want to select more than one line in given tag. ex.

content of .xml file
====================
<state>
 <text> hi this is first li </text>
 <sec> dsfn  sdlkf sfd </sec>
</state>
===================

i want to print all content between and tag. which and how i can use linux commands.
plz help me….thanks i advance.

  • 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-21T03:47:10+00:00Added an answer on May 21, 2026 at 3:47 am

    exec, execve or system calls: demo

    #include <stdlib.h>
    #include <unistd.h>
    
    int main(int argc, const char* args[])
    {
        exitcode = system("xsltprox textonly.xslt input.xml > output");
    //  exitcode = exec("xsltproc", "textonly.xslt", "input.xml");
        int exitcode;
    }
    

    Proceed to fopen output (or std::fstream reader(“output”) if you fancy). Note that system is quickly a security hole, so you shouldn’t use it in critical apps (like daemons).
    Using exec you could redirect. So you could perhaps open a pipe() from your program, fork(), in the child assign the stdout filedescriptor to the pipe() (see dup2 call) and exec in the child.

    The parent process can then read the output from the pipe without need for a temp file.
    All of this should be on a zillion tutorials, which I don’t have to the time to google for you right now.


    May I suggest using perl or shell script. If you post an actual example I could show you the code in both shell and c/c++

    Update here is how to do it with XSLT

    textonly.xslt:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0"
                    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="html" indent="yes"/>
        <xsl:template match="/">
            <xsl:for-each select="//*[text()]">
                <xsl:if test="text()">
                                    <xsl:value-of select="text()"/>:
                </xsl:if>
            </xsl:for-each>
        </xsl:template>
    </xsl:stylesheet>
    

    output demo:

    o399hee@OWW00837 ~/stacko
    $ xsltproc.exe textonly.xslt input.xml
    
     :
                 hi this is first li :
                 dsfn  sdlkf sfd :
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a program that will parse an Apache log file periodically to log
I am writing an assembly function to be called from C that will call
I am having some difficulty writing a function that will search through a directory
I find that I frequently end up writing a function that I always call
I am (slowly) writing an XML parser for some site definition files that will
I am writing a PHP function that will need to loop over an array
I'm writing a function that will be passed a lambda expression, and I want
I am writing a function that will take in the head of a linked
I'm writing a function that fishes out the src from the first image tag
Say for instance I was writing a function that was designed to accept multiple

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.