Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
To extract the lines between and including ones that start with <DTC> and end with </DTC>:

#!/usr/bin/perl -w use strict; while (<DATA>) { if (m|^\s*<DTC>| ... m|^\s*</DTC>|) { print; } } __DATA__ ...is your data consisting of the C program...
See: tutorial on Flip/Flop operator: Flipin good, or a total flop?

Lines extracted:

<DTC> <TroubleCode>1101</TroubleCode> <ShortDescription>The reductant pump needs to run slower than expect +ed to keep the pressure.</ShortDescription> <Classification>FAULT</Classification> <SelfHealing>No selfhealing</SelfHealing> <Erasability>erasable</Erasability> <RedetectedDegradation>No Degradation</RedetectedDegradation> <WarningLamp>No Warning Lamp</WarningLamp> <DirectDegradation>No Action</DirectDegradation> <Order>PRIMARY</Order> </DTC>
There are a number of Perl XML parsers that can deal with these lines after they have been extracted from the C code.

Update:
I looked again at the post and I think that the "C" code will not compile because the <DTC>...</DTC> stuff does not look like a comment block to the C compiler. I guess the blocks could be like:

/*XML doc start <DTC> <TroubleCode>1101</TroubleCode> <Classification>FAULT</Classification> <SelfHealing>No selfhealing</SelfHealing> <Erasability>erasable</Erasability> </DTC> XML doc end */
So that the C compiler will see the whole XML doc as a single comment block.

An alternate that is worth considering is Perl POD (Perl Plain Old Documentation) Perl POD. If you organize the "comments" in the C code right, the C compiler will be happy. And the Perl documentation generator will also be happy processing the raw C input file (a "=" as the first character on a line has special meaning). The Perl POD generators will make HTML web pages or man pages directly from the C source file, if the comments /*....*/ are done right.

/*Perl doc start =some heading in Perl POD ... lines =some other heading tag in Perl POD ..... lines =cut Perl doc end */

In reply to Re: extract comments from source code. by Marshall
in thread extract comments from source code. by veerubiji

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (7)
    As of 2014-07-12 07:32 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      When choosing user names for websites, I prefer to use:








      Results (238 votes), past polls