Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

section nesting

by prasadbabu (Prior)
on Jun 22, 2004 at 15:11 UTC ( [id://368757]=perlquestion: print w/replies, xml ) Need Help??

prasadbabu has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I am new to perl. I am doing validation tool in sgml, i want to check nesting in section tags. if the sections are improperly nested then i need to raise the error message. The error message should be identified by the content in id value of sec element. For example

My input

<sec id="4.1">

<sec id="4.2">

</sec></sec>

output

<sec id="4.1"></sec>

<sec id="4.2"></sec>

I am not having that much exposures in modules.

whether it is possible to check the nesting of tags without using the modules. My friend is capable of using xml twigs, but he is saying that it is not possible to do for sgml using xml twigs

Replies are listed 'Best First'.
Re: section nesting
by Abigail-II (Bishop) on Jun 22, 2004 at 15:54 UTC
    What defines "improper" nesting? Your example suggests no nesting is allowed at all. Is that the case? Anyway, I'd use a single tokenizer and a counter. Whenever you see a <sec id = "..."> token, increment the counter. Whenever you see a </sec> token, decrement the counter. Whenver the counter has a value unequal to either 0 or 1, you have "improper nesting" - that is, assuming no nesting at all can happen.

    Abigail

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://368757]
Approved by Limbic~Region
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-19 16:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found