开发者

Parsing XML files with regular expressions (Perl)

I am using regular expression to parse XML file (though regexp is not recommended for xml pa开发者_Go百科rsing, but i have to use regexp, no other go).

My doubt is how to skip commented lines in XML file, while parsing using Perl.

I want Perl to parse XML file, while skipping commented lines.

Can anyone help me, please.

Thanks Senthil .


As bad as this question is for many people, many answers to it are just as bad: use an XML parser, here's why, end of the discussion.

For me, the whole point of asking a question on stackoverflow is to obtain a solution. Have we provided a solution to OP? Not quite.

A more complete answer would offer some examples on how to parse xml. Here are some;

Can you provide an example of parsing HTML with your favorite parser?


If your problem is compiling XML libraries, you can try XML::Parser::Lite or XML::Parser::PurePerl which are pure perl modules requiring no compilation.

Or, you might be able to find pre-compiled packages of the non-pure-perl libraries. What OS are you on?


Please, do not parse XML with regular expressions, use XML parser instead.

At least you can write a simple finite-state machine based parser to process your XML. It's very simple to do it.


One way to do it is to strip commented lines prior to parsing.

$string =~ s/<!--.*?-->//gs;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜