Difference between revisions of "XML"
Jump to navigation
Jump to search
(Created page with "Generic remarks about XML. Comments start with '<!--' and end with '-->'. Comments cannot be nested. Regular expressions to remove comments (Perl code) <syntaxhighlight lang...") |
|||
Line 1: | Line 1: | ||
Generic remarks about XML. | Generic remarks about XML. | ||
− | Comments start with | + | Comments start with <code><nowiki><!--</nowiki></code> and end with <code><nowiki>--></nowiki></code>. |
Comments cannot be nested. | Comments cannot be nested. | ||
− | Regular expressions to | + | Regular expressions to check if we enter or leave a comment block |
<syntaxhighlight lang=perl> | <syntaxhighlight lang=perl> | ||
− | + | if ( ( $line =~ /-->/ ) && ( $incomment == 1 )) { | |
− | + | $incomment = 0; | |
− | if ( $line =~ / | + | $line =~ s/(<!--)?.*$&//; |
− | + | } | |
− | + | if ( $incomment == 0 ) { | |
− | + | if ( $line =~ /<!--/ ) { | |
− | + | $incomment = 1; | |
− | + | $line =~ s/$&.*?(-->)//; | |
− | + | if ( $1 ) { | |
− | + | $incomment = 0; | |
− | if ( $ | + | } |
− | + | } | |
− | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
+ | ;xmllint --noout <xmlfile> | ||
+ | :Test if <xmlfile> has valid xml and report errors. Without --noout the tree will be printed too. |
Revision as of 16:45, 14 August 2018
Generic remarks about XML.
Comments start with <!--
and end with -->
.
Comments cannot be nested.
Regular expressions to check if we enter or leave a comment block
if ( ( $line =~ /-->/ ) && ( $incomment == 1 )) {
$incomment = 0;
$line =~ s/(<!--)?.*$&//;
}
if ( $incomment == 0 ) {
if ( $line =~ /<!--/ ) {
$incomment = 1;
$line =~ s/$&.*?(-->)//;
if ( $1 ) {
$incomment = 0;
}
}
- xmllint --noout <xmlfile>
- Test if <xmlfile> has valid xml and report errors. Without --noout the tree will be printed too.