Difference between revisions of "XML"

From wiki
Jump to navigation Jump to search
 
Line 4: Line 4:
 
Comments cannot be nested.
 
Comments cannot be nested.
  
Regular expressions to check if we enter or leave a comment block
+
[[Perl]] [[Regular Expressions]] to check if we enter or leave a comment block
 
<syntaxhighlight lang=perl>
 
<syntaxhighlight lang=perl>
 
  if ( ( $line =~ /-->/ ) && ( $incomment == 1 )) {
 
  if ( ( $line =~ /-->/ ) && ( $incomment == 1 )) {
Line 19: Line 19:
 
   }
 
   }
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
Python module and code examples [[Python:XML]].
  
 
;xmllint --noout <xmlfile>
 
;xmllint --noout <xmlfile>
 
:Test if <xmlfile> has valid xml and report errors. Without --noout the tree will be printed too.
 
:Test if <xmlfile> has valid xml and report errors. Without --noout the tree will be printed too.

Latest revision as of 21:21, 7 September 2018

Generic remarks about XML.

Comments start with <!-- and end with -->. Comments cannot be nested.

Perl 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;
   }
  }

Python module and code examples Python:XML.

xmllint --noout <xmlfile>
Test if <xmlfile> has valid xml and report errors. Without --noout the tree will be printed too.